CasperJS senxAjax无法正常工作

时间:2015-06-26 05:54:01

标签: javascript casperjs

我有一个示例脚本:

var casper = require('casper').create();
var data, wsurl = 'http://api.github.com/users/mralexgray/repos';

casper.start('http://github.com/', function() {
    data = this.evaluate(function(wsurl) {
        return JSON.parse(__utils__.sendAJAX(wsurl, 'GET', null, false));
    }, {wsurl: wsurl});
});

casper.then(function() {
    require('utils').dump(data);
});

casper.run();

当我在我的控制台中运行时: $ casperjs api.js --web-security=no

我得到了null。为什么呢?

1 个答案:

答案 0 :(得分:0)

Use httpson wsurl,It worked for me.

var wsurl = 'https://api.github.com/users/mralexgray/repos';

casper.start('http://github.com/', function() {
    data = this.evaluate(function(wsurl) {
        try {
            return JSON.parse(__utils__.sendAJAX(wsurl, 'GET', null, false));
        } catch (e) {
            __utils__.echo(e);
        }

    }, {wsurl: wsurl});
});