beno_88 beno_88 - 4 months ago 97x
Ajax Question

phantomjs with ajax request

I would like use phantomjs with highcharts for generate a report. But for my chart, my data are in SQL database. Normally for generate my chart I use ajax request with a file query.cfc (coldfusion) and my chart works. But with phantomjs, if I add a function with my ajax request, I have an error in callback - error 404 but I don't no why. It's the same function what I use for my simple chart.

I launch phantomjs with that : phantomjs --web-security=no test.js

If you have an idea for my problem I take :)

var system = require('system');
var page = require('webpage').create();
var fs = require('fs');

// load JS libraries

// chart demo
var args = {
width: 600,
height: 500
page.onConsoleMessage = function(msg) {
page.includeJs("", function() {
var svg = page.evaluate(function(opt) {
$('body').prepend('<div id="container"></div>');

function test() {
type: "POST",
async: false,
url: "query3.cfc?method=test",
data: {
'arg1': 'aee',
'arg2': 'ss'
success: function(year) {
var lim_annee = jQuery.parseJSON(year);
error: function(jqXHR, exception) {
console.log('erreur ' + jqXHR.status);
console.log('erreur2 ' + exception);
//chart Code
return chart.getSVG();
}, args);

page.render('img.jpeg', {
format: 'jpeg',
quality: '100'


If you don't open a page in PhantomJS, it will stay at "about:blank" and "about:blank/query3.cfc?method=test" doesn't seem like a correct URL. Either use a correct URL to your ColdFusion server:

url: "http://localhost:port/query3.cfc?method=test",

or initialize the base domain in PhantomJS before doing anything else:

page.setContent("", "http://localhost:port/");

Remember that if you were to open simple local HTML files, you would need to use the "file://" protocol and remove any query string.

Also, loading multiple jQuery versions might break your script.