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';  
        }  
    ?>
  • 相关阅读:
    静态内存不能跨函数使用
    多级指针
    数组大小的动态分配
    luoguP1629 邮递员送信
    luoguP1119 灾后重建
    luoguP1395 会议
    树的重心
    luoguP5536 【XR-3】核心城市
    树的直径
    luoguP5836 [USACO19DEC]Milk Visits S
  • 原文地址:https://www.cnblogs.com/cymbidium/p/5221282.html
Copyright © 2011-2022 走看看