Home > Net >  Questions about ajax receive the background data
Questions about ajax receive the background data

Time:09-21

Beginners.net, verify student id repeat, how can I get at the front desk to get what I want value, no error, but no matter. I use the response wirte () or return values, the judgment of the ajax is executed from the first if statement of content, and with the response. The wirte (), web page will jump out of a 0, the returned data and the entire HTML, is irksome, strives for the great god save,

This is the HTML:


This is the js:
If (reg. Test (std_id. Value)) {
Isnum. InnerHTML="";
$. Ajax ({
Url: "WebForm1. Aspx/Is_Std,"
Async: true,
Data: {std_id: $(" # std_id "). Val ()},
Type: "post",
Success: the function (data) {
Var getfun=& lt; % %=Is_Std () & gt;;
The console. The log (getfun)
{if (getfun="1")
Isnum. InnerHTML="student id";
}
Else if (getfun="0") {
Isnum. InnerHTML="student number does not exist, you can use";
}

},
Error: function (data) {
Alert (" wrong ");
}
})
}

This is the background:
Protected void Page_Load (object sender, EventArgs e)
{
load();
Is_Std ();
}

Public string Is_Std ()
{
OpenDatabase ();
String number=Request [" std_id "];
If (JudgeStd (number)=="1")
{
Conn. Close ();
//Response. Write (" 1 ");
return "1";
}
The else
{
Conn. Close ();
//Response. Write (" 0 ");
return "0";
}
//Response. Flush ();
//Response. The End ();

}

Public string JudgeStd (string STD)
{
String sql1="select * from student_info where student_id='" + STD +"' ";
CMD=new SqlCommand (sql1, conn);
SqlDataReader sqlrd1;
Sqlrd1=CMD. ExecuteReader ();
If (sqlrd1. HasRows)
{
Sqlrd1. Close ();
return "1";
}
The else
{
Sqlrd1. Close ();
return "0";
}

}

CodePudding user response:

WebForm1. Aspx page cannot have HTML code, or it will output, or you change to ashx general handler

CodePudding user response:

Or by formal way, ajax request ashx general processing program files, only

CodePudding user response:

The background Response. Write (" 1 "); Response.End();
Front desk js judgment you write wrong, there should be an if (getfun=="1") is not an if (getfun="1")
  • Related