Jquery $. Ajax method example

Source: Internet
Author: User

To avoid returning the entire page of HTML source code after Ajax requests, clear the response value.

Httpcontext. current. response. clear (); httpcontext. current. response. write ("[{sname: \" "+ strsname +" \ ", fname: \" "+ strfname +" \ "}]");

Httpcontext. Current. response. End ();

 

// Html front-end

Function searchcorpinfo (){
// Debugger;
$. Ajax ({
Type: "Post ",
URL: "managecorpinfo. aspx? Mode = getcorpinfo & code = "+ $ (" # stockid _ "). Val (),
Success: function (MSG ){
If (MSG! = "Exception "){
VaR dt = eval (MSG );
If (DT! = NULL & DT! = Nan ){
$. Each (DT, function (KK, vv ){
VaR simplename = VV ["sname"];
VaR fullname = VV ["fname"];

$ ("# Txtsimplename"). Val (simplename );
$ ("# Txtcorpname"). Val (fullname );
});

}
}
Else {
$ ("# Txtsimplename"). Val ("");
$ ("# Txtcorpname"). Val ("");
}
},
Error: function (){
}
});
}

 

// The background code load event

If (request. querystring ["Mode"]! = NULL)
{
If ("getcorpinfo" = request. querystring ["Mode"]. tostring ())
{
If (request. querystring ["code"]! = NULL)
{
If (request. querystring ["code"]. tostring (). Length = 6)
Searchcorpinfo (request. querystring ["code"]. tostring ());
}
}
}

// Obtain the company name and short name based on the entered company code
Public void searchcorpinfo (string corpcode)
{
// Obtain the company name
Corpinfomanagedb objc = new corpinfomanagedb ();
Datatable dtcorp = objc. companyinfo_getinfo (corpcode, "", 0 );
If (objc. errormsg. length> 0)
{
Httpcontext. Current. response. Clear ();
Httpcontext. Current. response. Write ("exception ");
Httpcontext. Current. response. End ();
}
If (dtcorp. Rows. Count = 0)
{
Httpcontext. Current. response. Clear ();
Httpcontext. Current. response. Write ("exception ");
Httpcontext. Current. response. End ();
}
String strsname = dtcorp. Rows [0] ["simplename"]. tostring ();
String strfname = dtcorp. Rows [0] ["corpname"]. tostring ();
Httpcontext. Current. response. Clear ();

Httpcontext. Current. response. Write ("[{sname: \" "+ strsname +" \ ", fname: \" "+ strfname +" \ "}]");
Httpcontext. Current. response. End ();
}

 

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.