I am new to CasperJS and laravel. I need a help, I want to send an associative array(all the contents in that array at once) to CasperJS from a function, currently i am encoding it using the JSON_encode as the CasperJS script doesn't take array. The following piece of code encodes the array and sends as one string. On the other side i am fetching the string in casperJS script and unable to decode the JSON. The format of json changes on reaching the casperJS script.
$array = array
(
[1] => http://www.xxxx.com,
[2] => http://www.yyyy.com,
[3] => http://www.zzzz.com
);
$data_fetch=json_encode($array);
$casperjs = new CasperJS;
$result = $casperjs->execute($this->script2,$data_fetch);
print_r($data_fetch);
which outputs after encoding the array
{"1":"http://www.xxxx.com","2":"http://www.yyyy.com","3":"http://www.zzzz.com"}
The CasperJS script
var system = require('system');
var casper = require('casper').create({
verbose: true,
logLevel: 'error',
pageSettings: {
loadImages: false,
loadPlugins: false
}
});
var data = system.args[4];
casper.start(function() {
var decode=json.stringify(data);
});
casper.run();
when you check the input in 'data' variable using console.log it is
{1:http://www.xxxx.com,2:http://www.yyyy.com,3:http://www.zzzz.com}
which is different from the json.encode it is omitting double quotes, because of different formats i am unable to decode the content.
Can anyone help why is it doing that way?? Any solution for this?? OR is there any other better way to pass an array to casper and return back the result as an array.