javascript - Send an Ajax request in CasperJS and loop through results -


i trying fetch json values(mainly urls) call , assign variable. ultimlately loop through values , open each url casper. however, seen have incorrect concept on fetching values through ajax call casperjs. read through documentation dont seem understand why still getting error referenceerror: can't find variable: __utils__?

casper.start(); var url = "http://dev.web-ui.com/generate.php";  casper.then(function(url) {     var results = __utils__.sendajax(url, "get"); });  casper.run(); 

you have @ least 2 problem:

  • the url parameter not url, last loaded page resource object contains url.

  • __utils__ not available outside of page context. can require if want, won't fix problem, because dummy document.location outside of page context has not same domain url want query, request may fail due cross-domain restrictions. it's best in page context.

example code:

casper.then(function(resource) {     var results = this.evaluate(function(url){          return __utils__.sendajax(url, "get");     }, resource.url);     this.echo(results); }); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

android - Go back to previous fragment -