栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

单击一个按钮以在PHP中运行casperJS并在带有按钮的同一PHP页面中生成结果

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

单击一个按钮以在PHP中运行casperJS并在带有按钮的同一PHP页面中生成结果

因此,我认为可以使用AJAX 在同一页面上显示 casperjs 回显的结果。我用两个按钮制作了一个HTML页面:1) 运行casperjs
AJAX
以运行AJAX,以及2) 运行casperjs
以简单地加载执行casperjs脚本并将结果打印到新页面中的PHP页面。这是HTML(在“如何链接外部javascript文件onclick按钮以实现AJAX按钮单击的帮助下”):

<!DOCTYPE html><html>    <head>        <title>casperJS testing</title>    </head>    <center>    <body>    <div id="mainContent"><p>Welcome to the Automated Testing Utility</p><table><tr>  <td><button id="button_AJAX">Run casperjs AJAX</button></td>  <td><form action="runscript.php">    <input type="submit" value="Run casperJS"></form></td> </tr></table>    </div>    <script type="text/javascript">    var button = document.getElementById('button_AJAX');    button.onclick = function(){        var script = document.createElement("script");        script.type = "text/javascript";        script.src = "casperjsajax.js";         document.getElementsByTagName("head")[0].appendChild(script);        return false;    }    </script>    </center>    </body></html>

casperjsajax.js 代码(带的帮助下JS基础培训):

// 1: Create the request var myRequest;// feature check!if (window.XMLHttpRequest) {  // does it exist? we're in Firefox, Safari etc.    myRequest = new XMLHttpRequest();} else if (window.ActiveXObject) { // if not, we're in IE    myRequest = new ActiveXObject("Microsoft.XMLHTTP");}// 2: Create an event handler for request to call backmyRequest.onreadystatechange = function(){    if (myRequest.readyState === 4) {        var p = document.createElement("p");        var t = document.createTextNode(myRequest.responseText);        p.appendChild(t);        document.getElementById("mainContent").appendChild(p);    }};// Open and send itmyRequest.open('GET', 'scriptresults.php', true);// any parameters?myRequest.send(null);

scriptresults.php 代码:

<?phpecho "Here are your test results!";echo "<br />";echo exec("/home/user/casperjs/bin/casperjs /full/path/to/your_script.js");?>

以及非AJAX 的 runscript.php 链接

<html><head><title>casperJS Test Results</title></head><body>    <center><p>Here are your results!</p><br><?php    echo exec("/usr/local/bin/casperjs /full/path/to/your_script.js");?>    </center>   </body></html>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/404076.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号