easyUI 通過ajax的方式提交Form

@author YHC

這個教程向你展示使用easyui提交一個form,我們創建一個示例form和name, email 和phone 字段.通過使用form 插件我們改變form為ajax form,form提交所有

字段到後臺服務器,服務器處理和發送一些數據返回到前端頁面,我們顯示數據和顯示出來.

 \

 查看   Demo

 

創建 Form
[html]
<p style="padding:3px 2px;border-bottom:1px solid #ccc">Ajax Form</p>   
<form id="ff" action="form1_proc.php" method="post">   
    <table>   
        <tr>   
            <td>Name:</td>   
            <td><input name="name" type="text"></input></td>   
        </tr>   
        <tr>   
            <td>Email:</td>   
            <td><input name="email" type="text"></input></td>   
        </tr>   
        <tr>   
            <td>Phone:</td>   
            <td><input name="phone" type="text"></input></td>   
        </tr>   
        <tr>   
            <td></td>   
            <td><input type="submit" value="Submit"></input></td>   
        </tr>   
    </table>   
</form>   

<p style="padding:3px 2px;border-bottom:1px solid #ccc">Ajax Form</p> 
<form id="ff" action="form1_proc.php" method="post"> 
    <table> 
        <tr> 
            <td>Name:</td> 
            <td><input name="name" type="text"></input></td> 
        </tr> 
        <tr> 
            <td>Email:</td> 
            <td><input name="email" type="text"></input></td> 
        </tr> 
        <tr> 
            <td>Phone:</td> 
            <td><input name="phone" type="text"></input></td> 
        </tr> 
        <tr> 
            <td></td> 
            <td><input type="submit" value="Submit"></input></td> 
        </tr> 
    </table> 
</form> 

改變為Ajax form
[javascript] view plaincopyprint?$('#ff').form({   
    success:function(data){   
        $.messager.alert('Info', data, 'info');   
    }   
});   

$('#ff').form({ 
    success:function(data){ 
        $.messager.alert('Info', data, 'info'); 
    } 
});  服務器端代碼
form1_proc.php

[php] view plaincopyprint?$name = $_POST['name'];   
$email = $_POST['email'];   
$phone = $_POST['phone'];   
   
echo "Your Name: $name <br/> Your Email: $email <br/> Your Phone: $phone";   

$name = $_POST['name']; 
$email = $_POST['email']; 
$phone = $_POST['phone']; 
 
echo "Your Name: $name <br/> Your Email: $email <br/> Your Phone: $phone"; 
 

 

 作者:yhc13429826359
 

 

 

發佈留言