JS Required for reference:
In http://www.malsup.com/jquery/form/#download download:http://malsup.github.com/jquery.form.js
Downloads in http://jquery.com/:http://code.jquery.com/jquery-1.7.2.min.js
Precautions:
DataType: "JSON",//get the way to set this property again
//Note: From If it is runat= "server" then the option URL can only be submitted to its own. aspx, if not, it may be submitted to another. aspx receive.
Note: The <input tag in the from must have the name attribute, otherwise only the ID request.form[] will be added after the label.
It will return the HTML file content of the entire page without first clear, and do not use Response.Write (); it should be: HttpContext.Current.Response.Write, note
HttpContext.Current.Response.ContentType = "text/html";
HttpContext.Current.Response.Clear ();
Example code:
aspx page<%@ page language= "C #" autoeventwireup= "true" codebehind= "JqueryFormAjaxSubmit.aspx.cs" inherits= " Garytestpro.jqueryformajaxsubmit "%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script type= "Text/javascript" src= "Js/jquery/jquery-1.7.1.min.js" ></script>
<script type= "Text/javascript" src= "Js/jquery/jquery.form.js" ></script>
<script type= "Text/jscript" language= "JScript" >
function Subinfo () {
$ ("#Order"). Append ("<input name=txtdns value=\" DNS resolution \ "Id=txtdns type=\" text\ "/>");
$ ("#Order"). Append ("<input name=txtip value=\" IP address \ "Id=txtip type=\" text\ "/>");
var options = {
Beforesubmit:function () {
return true;
},
URL: ' jqueryformajaxsubmit.aspx? MODE=SF ',
Type: ' POST ',
DataType: "JSON",//get the way to set this property again
Success:function (data) {
if (data = = "") {
document.getElementById (' Order '). Style.display = "None";
Alert ("Operation succeeded!");
}
else {
alert (data);
}
},
Error:function () {
Request Error Handling
Alert ("Error");
}
};
Note: The From If is runat= "server" that option URL can only be submitted to its own. aspx, if not, it may be submitted to another. aspx receive.
Note: The <input tag in the from must have the name attribute, otherwise only the ID request.form[] will be added after the label.
$ ("#form1"). Ajaxsubmit (options);
}
</script>
<body>
<form id= "Form1" runat= "Server" method= "POST" >
<div>
<div id= "Order" >
</div>
<input name= "txtname" value= "Monday" id= "txtname" type= "text"/>
<input name= "Txtuser" value= "Tuesday" id= "Txtuser" type= "text"/>
<a href= "javascript:void (0);" onclick= "Subinfo ();" > Submit </a>
</div>
</form>
</body>
Aspx.cs Code:
protected void Page_Load (object sender, EventArgs e)
{
if (request.form["txtname"]! = NULL)
{
String sName = request.form["Txtname"]. ToString ();
}
if (request.form["Txtdns"]! = NULL)
{
String sdns = request.form["Txtdns"]. ToString ();
Returns the HTML file content of the entire page without first clear
HttpContext.Current.Response.Clear ();
HttpContext.Current.Response.ContentType = "text/html";
HttpContext.Current.Response.Write ("{result:true}");
HttpContext.Current.Response.End ();
}
Application considerations of JQuery Form Ajaxsubmit (Options) in ASP.