[英]Sending Ajax Request with PhantomJS to a local ColdFusion server
I would like use PhantomJS with highcharts for generate a report. 我想将PhantomJS与highcharts一起使用以生成报告。 But for my chart, my data are in SQL database.
但是对于我的图表,我的数据在SQL数据库中。 Normally, for generating my chart I use ajax request with a file query.cfc (coldfusion) and my chart works.
通常,为了生成我的图表,我将ajax请求与文件query.cfc(oldfusion)一起使用,并且我的图表可以工作。 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.
但是使用PhantomJS时,如果我在ajax请求中添加了一个函数,则回调中会出现错误-错误404,但我不知道为什么。 It's the same function what I use for my simple chart.
它与我用于简单图表的功能相同。
I launch PhantomJS with: phantomjs --web-security=no test.js
我使用以下
phantomjs --web-security=no test.js
启动PhantomJS: phantomjs --web-security=no test.js
var system = require('system');
var page = require('webpage').create();
var fs = require('fs');
// load JS libraries
page.injectJs("jquery-2.1.1.js");
page.injectJs("highcharts.js");
page.injectJs("exporting.js");
// chart demo
var args = {
width: 600,
height: 500
};
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
var svg = page.evaluate(function(opt) {
$('body').prepend('<div id="container"></div>');
function test() {
$.ajax({
type: "POST",
async: false,
url: "query3.cfc?method=test",
data: {
'arg1': 'aee',
'arg2': 'ss'
},
success: function(year) {
var lim_annee = jQuery.parseJSON(year);
console.log('success');
},
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'
});
phantom.exit()
});
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. 如果您未在PhantomJS中打开页面,它将停留在“ about:blank”,并且“ about:blank / query3.cfc?method = test”似乎不是正确的URL。 Either use a correct URL to your ColdFusion server:
使用正确的URL到您的ColdFusion服务器:
url: "http://localhost:port/query3.cfc?method=test",
or initialize the base domain in PhantomJS before doing anything else: 或在执行其他操作之前在PhantomJS中初始化基本域:
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. 请记住,如果要打开简单的本地HTML文件,则需要使用“ file://”协议并删除所有查询字符串。
Also, loading multiple jQuery versions might break your script. 另外,加载多个jQuery版本可能会破坏您的脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.