现在有个页面用了ajax 提交到一个php文档。以前有什么错误 php文档直接输出错误相关的内容。现在有了ajax什么都在当页显示。怎么能测试呢?

解决方案 »

  1.   

    用js的调试方法啊。alert/document.write 都可。还可借助firebug工具跟踪。
      

  2.   

    单独调试php,待无误后再联调
      

  3.   

    错误也会被ajax收到的 打印出responseText就行了。。是这么拼吧
      

  4.   

    一般都是单独调试好php代码后,然后联调。
    至于怎么调试。一般都是自己伪造请求数据模拟请求过程.
      

  5.   

    php后台echo出值,让AJAX在前台获取,然后alert
      

  6.   

    用firebug,在控制台里面可以看到ajax请求返回的值,如果出错的话也能看到报错信息。
      

  7.   

    仅供参考:#manage_action_class.php
    if(isset($_GET['pot'])){
      echo "端口正常";
    }
    var xmlHttp; function createXMLHttpRequest() {
    if(window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    }
    function routeList(){
    createXMLHttpRequest();
    var port = document.condsys.netport;
    for(var i=0; i<port.options.length; i++){
    if (port.options[i].selected == true){
    var pot = port.options[i].text;
    } //end if
    }
    url = "manage_action_class.php?pot="+pot+"&ran="+Math.random();
    method = "GET";
    xmlHttp.open(method,url,true);
    xmlHttp.onreadystatechange = showList;
    xmlHttp.send(null);
    } function showList(){
    if (xmlHttp.readyState == 1){
    document.getElementById("route").innerHTML="响应中……";
    }else{
    document.getElementById("route").innerHTML="";
    }
    if (xmlHttp.readyState == 4){
    if (xmlHttp.status == 200){
    var text = xmlHttp.responseText;
                                    //在此将获取到的后台信息打印出来,如果是你想要的信息再将其屏蔽
                                    alert("text-->>"+text);
                                    return;
    document.getElementById("route").innerHTML = text;
    }else {
    alert("response error code:"+xmlHttp.status);
    }
    }
    }
    <div id="route"></div>
      

  8.   

    直接alert
    错误也会出来的~~
      

  9.   

    你如果是用get方式传值,你直接模拟一个连接访问php页面直接看,如果是post你就写个测试用的表单提交到对应的页面,再就是楼上说道的将返回信息用js输出
      

  10.   

    谢谢大家,你们说的太好了.CSDN论坛确实网友比较热情