javascript - CasperJS POST AJAX is not working -
i'm working on sending data through ajax. code working, ajax request not working. data sent not saved.
i have tried using websecurityenabled: false
, still doesn't work.
this how i'm trying it:
var casper = require("casper").create({ loglevel: "error", //debug verbose: true, pagesettings: { loadimages: true, // not load images loadplugins: false, // not load npapi plugins (flash, silverlight, ...) websecurityenabled: false // ajax } }); ........................ var save_file="http://aaa.com/js_save.php"; for(var ii=0; ii<title_link.length; ii++) { this.echo(title_link[ii]); //var save_data = tlink.serialize(); var save_data = {"title":"title", "link":title_link[ii]}; jsonobject_fields = this.evaluate(function(save_file) { params = save_data; try { return json.parse(__utils__.sendajax(save_file, 'post', params, false)); } catch (e) { console.log("error in fetching json object"); } }, {save_file : save_file}); try{ //require("utils").dump(json.stringify(jsonobject_fields.name)); } catch(e) { console.log("error is: "+e); } } //
i don't understand question, code-wise need explicitly pass variables page context. casper.evaluate
sandboxed , way pass data between casper context , page context using arguments , return value. variables defined outside cannot used inside of casper.evaluate
.
you need pass save_data
explicitly page context:
var save_data = {"title":"title", "link":title_link[ii]}; jsonobject_fields = this.evaluate(function(save_file, save_data) { try { return json.parse(__utils__.sendajax(save_file, 'post', save_data, false)); } catch (e) { console.log("error in fetching json object"); } }, save_file, save_data);
Comments
Post a Comment