日期:2014-05-16  浏览次数:20717 次

php和ajax的问题
现在php实现一个弹出框,但是我想在弹出框里面调用PHP程序,后面背景不跟着改变,只有弹出框进行刷新。我知道要用ajax,各位高手能稍微具体带点代码地说明一下么,不胜感激。。。

<form target="formSubmit" defaultbutton="btn" method="post" id="submitForm" name="submitForm">
  <div class="chakanphone">
  <p style="font-size: 16px" >您确定要执行吗? <br><input type="button" onclick="location.href='/submit/index/<?=$id;?>'" style="font-weight: bold; font-size: 14px" value="立即执行" class="guanbi"></p>
  </div>
  </form>
上面的代码就是调用PHP里面的一个方法,我想实现AJAX在弹出框里面调用然后弹出框里面返回值。

------解决方案--------------------
HTML code
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript">
            function execute(){
                xmlhttp.onreadystatechange=function()
                {
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                        // 在这里显示服务器脚本返回的内容
                        //document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
                    }
                }
                xmlhttp.open("POST","/submit/index/<?=$id;?>",true);
                xmlhttp.send();
            }
        </script>
    </head>
    <body>
        <form target="formSubmit" defaultbutton="btn" method="post" id="submitForm" name="submitForm">
            <div class="chakanphone">
                <p style="font-size: 16px" >您确定要执行吗? <br>
                    <input type="button" onclick="location.href='/submit/index/<?=$id;?>'" style="font-weight: bold; font-size: 14px" value="立即执行" class="guanbi">
                </p>
            </div>
        </form>
    </body>
</html>