• ajax php POST 提交例子


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

    <title>利用XMLHTTP无刷新添加数据</title>

    <script type="text/javascript">

    <!--

    function AddDatapost(sUserId,sUserName)

    {

    var objxmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

    //sUserId=escape(sUserId);

    //sUserName=escape(sUserName);

    var userinfo="userid="+sUserId+"&username="+sUserName;

    objxmlhttp.open("Post","ajax_output.php",false);

    //需要定义发送的头

    objxmlhttp.setRequestHeader("Content-Length",userinfo.length)

    objxmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")

    objxmlhttp.send(userinfo)

    //清空输入数据

    document.all.userid.value="";

    document.all.username.value="";

    alert(objxmlhttp.responseText);

    document.getElementById("xxxx").innerHTML= objxmlhttp.responseText;

    }

    //-->

    </script>

    </head>

    <body>

    <input type="text" name="userid"><br>

    <input type="text" name="username"><br>

    <input type="button" onclick="AddDatapost(document.all.userid.value,document.all.username.value)" value="AdddData">

    </body>

    </html>

    <?

         echo $_POST['userid'];

         echo $_POST['username'];

        

    ?>

    <script language="javascript">

    var xmlHttp;

    function sendCall(url, params) {

    if (window.ActiveXObject) {

    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

    } else if (window.XMLHttpRequest) {

    xmlHttp = new XMLHttpRequest();

    }

    xmlHttp.onreadystatechange = callBack;

    xmlHttp.open('POST', url, true);

    xmlHttp.setrequestheader("content-length",params.length);

    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.send(params);

    }

    function callBack() {

    if (xmlHttp.readyState == 4) {

    if (xmlHttp.status == 200) {

    document.getElementById("title").innerHTML = xmlHttp.responseText ;

    }

    }

    }

    function submitMsgForm(){

    var receiver = document.getElementById("receiver").value;

    var title = document.getElementById("title").value;

    var content = document.getElementById("content").value;

    var params = "receiver="+receiver+"&title="+title+"&content="+content;

    var url = "ajax_output.php";

    sendCall(url, params);

    }

    </script>

    <form name="form" action="" method="post">

    <div id="xxxx"></div>

    <TABLE>

    <TR>

    <TD>receiver</TD>

    <TD><INPUT TYPE="text" NAME="receiver" id="receiver" ></TD>

    </TR>

    <TR>

    <TD>title</TD>

    <TD><INPUT TYPE="text" NAME="title" id="title" ></TD>

    </TR>

    <TR>

    <TD>content</TD>

    <TD><INPUT TYPE="text" NAME="content" id="content" ></TD>

    </TR>

    <TR>

    <TD></TD>

    <TD><INPUT TYPE="button" name="submit" value="submit" onclick="submitMsgForm()"></TD>

    </TR>

    </TABLE>

    </form>

    <?

    $receiver = $_POST['receiver'];

    $title = $_POST['title'];

    $content =$_POST['content'];

    $content = $receiver . $title . $content;

    echo $content;

    ?>

  • 相关阅读:
    Effective Java 03 Enforce the singleton property with a private constructor or an enum type
    Effective Java 02 Consider a builder when faced with many constructor parameters
    Effective Java 01 Consider static factory methods instead of constructors
    sencha touch 手势识别左右滑动
    sencha touch textarea 手机上不显示滚动条,且不能滚动
    IBM Worklight OutOfMemoryError: Java heap space 错误
    shopnc-setNcCookie-后台验证码
    shonc-聊天im工具配置
    ecstore开启发送邮件日志,并且排查邮件发布出去原因
    php上传导入文件 nginx-502错误
  • 原文地址:https://www.cnblogs.com/zzxap/p/2176007.html
Copyright © 2020-2023  润新知