Jquery automatically encapsulates the form form as a concrete implementation of json
- 2020-03-30 02:22:46
- OfStack
Front page:
Back-end processing:
<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>
Mobile phone:
</th>
<td>
<input type="text" name="model.Mobile" id="txtMobile" maxlength="11" />
</td>
<th>
Password:
</th>
<td>
<input type="password" name="model.Pwd" id="txtPwd" maxlength="11" />
</td>
</tr>
<tr>
<td style="text-align: center;" colspan="2">
<input type="button" value=" mention Hand in " style="padding-top: 3px;" name="butsubmit"
id="butsubmit" />
</td>
</tr>
</table>
</form>
//Prompt to server
$(function () {
$("#butsubmit").click(function () {
var data = $("#tf").serializeArray(); //Automatically encapsulates the form form as json
// $.ajax({
// type: "Post", // access WebService use Post Way to request
// contentType: "application/json", //WebService Returns the Json type
// url: "/home/ratearticle", // call WebService Combination of address and method name ---- WsURL/ The method name
// data: data, // Here are the parameters to be passed, and the format is data: "{paraName:paraValue}", We'll see that below
// dataType: 'json',
// success: function (result) { // The callback function, result , the return value
// alert(result.UserName + result.Mobile + result.Pwd);
// }
// });
$.post("/home/ratearticle", data, RateArticleSuccess, "json");
});
})
//The results showed
function RateArticleSuccess(result) {
alert(result.UserName + result.Mobile + result.Pwd);
}</span>
Back-end processing:
<span style="font-size:14px;">public JsonResult ratearticle(UserInfo model)
{
return Json(model);
}</span>