zoukankan      html  css  js  c++  java
  • php 异步提交表单

    XML/HTML code
     
    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    <form name="touzi" method="post">
    <table>
        <tr>
            <td>客户类型</td>
            <td><input type="radio" name="customer-type" value="个人客户" id="0"/><input type="radio" name="customer-type" value="机构客户" id="1"/></td>
        </tr>
        <tr>
            <td>联系人</td>
            <td><input type="text" id="username"/></td>
        </tr>
        <tr>
            <td>联系电话</td>
            <td><input type="text" id="mobile"/></td>
        </tr>
        <tr>
            <td>E-mail</td>
            <td><input type="text" id="email"/></td>
        </tr>
        <tr>
            <td>联系地址</td>
            <td><input type="text" id="address"/></td>
        </tr>
        <tr>
            <td>邮编</td>
            <td><input type="text" id="postcode"/></td>
        </tr>
        <tr>
            <td>内容</td>
            <td><textarea id="customer-content"></textarea></td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" value="tijiao" onclick="submitForm()"/></td>
        </tr>
    </table>
    </form>



    JavaScript code
     
    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    function submitForm(){
        var xmlHttp = createXmlHttp();  
        if(!xmlHttp) {  
            alert("您的浏览器不支持AJAX!");  
            return 0;  
        }  
           
        var url = 'phpmail.php';  
        var postData = "";  
        postData = "username=" + document.getElementById('username').value;  
        postData += "t=" + Math.random();  
     
        xmlHttp.open("POST", url, true);  
        xmlHttp.setRequestHeader("Content-Type""application/x-www-form-urlencoded");  
        xmlHttp.onreadystatechange = function() { 
            alert(xmlHttp.status);
            if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {  
         
                if(xmlHttp.responseText == '1') {  
                    alert('post successed');  
                }  
            }  
        }  
        xmlHttp.send(postData);
    }
     
    function createXmlHttp() {  
        var xmlHttp = null;  
            
        try {  
            //Firefox, Opera 8.0+, Safari  
            xmlHttp = new XMLHttpRequest();  
        catch (e) {  
            //IE  
            try {  
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");  
            catch (e) {  
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  
            }  
        }  
            
        return xmlHttp;  
    }  
        



    php

    PHP code
     
    ?
    1
    2
    3
    4
    5
    <?php  
        if(isset($_POST['username']) {  
            echo '1';  
        }  
    ?>
  • 相关阅读:
    关于二进制的利用
    2017年浙江中医药大学程序设计竞赛 Solution
    2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest Solution
    2018-2019 ACM-ICPC, Asia Shenyang Regional Contest Solution
    2018-2019 ACM-ICPC, Asia Nanjing Regional Contest Solution
    AtCoder Grand Contest 029 Solution
    BZOJ 3307: 雨天的尾巴
    Codeforces Round #526 (Div. 2) Solution
    2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution
    [HZNUOJ] 博
  • 原文地址:https://www.cnblogs.com/cymbidium/p/5221282.html
Copyright © 2011-2022 走看看