jquery automatically encapsulates form forms into JSON-specific implementations _jquery

Source: Internet
Author: User
Front page:
Copy Code code as follows:

<span style= "FONT-SIZE:14PX;" > <form action= "" method= "Post" id= "TF" >
<table width= "100%" cellspacing= "0" cellpadding= "0" border= "0" >
<tr>
<th>
Name:
</th>
<td>
<input type= "text" id= "txtUserName" "name=" model. UserName "/>
</td>
<th>
Contact Mobile:
</th>
<td>
<input type= "text" name= "model. Mobile "id=" Txtmobile "maxlength="/>
</td>
<th>
Password:
</th>
<td>
<input type= "password" name= "model." Pwd "id=" txtpwd "maxlength="/>
</td>
</tr>
<tr>
&LT;TD style= "Text-align:center" colspan= "2" >
<input type= "button" value= "submitted" style= "PADDING-TOP:3PX;" Name= "Butsubmit"
Id= "Butsubmit"/>
</td>
</tr>
</table>
</form>
Prompt to Server
$ (function () {
$ ("#butsubmit"). Click (function () {
var data = $ ("#tf"). Serializearray (); Automatically encapsulate form forms into JSON


$.ajax ({
Type: "POST",//Access WebService use POST method request
ContentType: "Application/json",//webservice returns JSON type
URL: "/home/ratearticle",//Calling WebService address and method name combination----Wsurl/Method name
Data:data,//Here is the parameter to pass, the format is data: "{Paraname:paravalue}", the following will see
DataType: ' JSON ',
Success:function (Result) {//callback function, result, return value
Alert (result. UserName + result. Mobile + result. PWD);
// }
// });

$.post ("/home/ratearticle", Data, Ratearticlesuccess, "json");
});
})



Results show

function ratearticlesuccess (Result) {
Alert (result. UserName + result. Mobile + result. PWD);
}</span>

Back-end Processing:
Copy Code code as follows:

<span style= "FONT-SIZE:14PX;" >public Jsonresult ratearticle (UserInfo model)
{
return Json (model);
}</span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.