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 handlerCodePudding user response:
Or by formal way, ajax request ashx general processing program files, onlyCodePudding 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")