Run/Execute CasperJS script by clicking a button o

2020-03-31 05:52发布

问题:

I have a casperJS script which returns a JSON when run on commandline. I want to have an arrangement such that 1) I create a webpage 2) On clicking a button on the webpage the casperJS scripts gets executed at the server side and post/return the result back to the webpage.

How can i do the same.

EDIT: I am invoking an AJAX process written in php on clicking the buttom. The php script contains echo exec('casperjs sample.js');
It returned nothing but on checking the webserver error log I got the error
'casperjs' is not recognized as an internal or external command, operable program or batch file.

PS: It running absolutely fine via commandline.

EDIT2
I changed the php script to:
echo exec('C:\casperjs\batchbin\casperjs .\sample.js');
The error got modified to :
'phantonjs' is not recognized as an internal or external command, operable program or batch file.

回答1:

I have found solution from my post on google group

https://groups.google.com/forum/#!topic/casperjs/7Lps6TiX-78

It worked by moving CasperJS & PhantomJS executable file in the directory server (/html)