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 ();
}