通过单击网页上的按钮运行/执行 CasperJS 脚本 [英] Run/Execute CasperJS script by clicking a button on webpage

查看:36
本文介绍了通过单击网页上的按钮运行/执行 CasperJS 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 casperJS 脚本,它在命令行上运行时返回一个 JSON.我想要这样的安排1)我创建了一个网页2) 单击网页上的按钮后,casperJS 脚本将在服务器端执行并将结果发布/返回给网页.

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.

我该怎么做.

我在单击按钮时调用用 php 编写的 AJAX 进程.php脚本包含echo exec('casperjs sample.js');
它没有返回任何东西,但在检查网络服务器错误日志时我得到了错误
'casperjs' 不被识别为内部或外部命令,可运行的程序或批处理文件.

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:它通过命令行运行得非常好.

PS: It running absolutely fine via commandline.

EDIT2
我将 php 脚本更改为:
echo exec('C:\casperjs\batchbin\casperjs .\sample.js');
错误已修改为:
'phantonjs' 不被识别为内部或外部命令,可运行的程序或批处理文件.

推荐答案

我从我在 google group 上的帖子中找到了解决方案

I have found solution from my post on google group

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

它通过移动 CasperJS &目录服务器中的 PhantomJS 可执行文件(/html)

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

这篇关于通过单击网页上的按钮运行/执行 CasperJS 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆