Application considerations of JQuery Form Ajaxsubmit (Options) in ASP.

Source: Internet
Author: User
Tags httpcontext

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.

Related Article

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.