In using the JQuery class library Ajax, I found a very strange problem, on the Internet to find a jquery call. Net background method, using the URL to pass the parameters are no problem, you can normally execute, the example will be written out later, but called. Net background method is strange, breakpoint debugging, only into the Load event, and do not call to execute the method, to find students help, the students did a child example can be executed, through the QQ Remote Assistance, the problem is not resolved, is very depressed, I took his code copy a copy, it can be implemented, I was puzzled, A short line of more than 10 lines of code is written exactly the same, I opened my eyes to see, and finally did not find the problem, simply CTRL + + CTRL + +, this should be no problem, it must not be wrong, oh, the result is not the implementation of the method to call, and then I used vs2008 tried, the result of the problem, Then put the VS2008 code on the VS2005 page, or not, I really do not know where the problem, VS2005 also have executed successfully, that is, the students to give the lines of code, how to try on the vs2008 is no problem, I posted the code, Welcome to study and discuss, and ask questions.
VS2008 version of the code
Front Code
<script type= "Text/javascript" language= "JavaScript" src= "Jquery.min.js" ></script>
<script type= "Text/javascript" language= "JavaScript" >
$ (function () {
$ ("#btn"). Click (function () {
$.ajax ({
Type: "Post",
URL: "Default.aspx/hello",
ContentType: "Application/json",
DataType: "JSON",
Data: "{str: ' name '}",
Success:function (data) {
alert (DATA.D);
},
Error:function (Err) {
Alert ("Error:" +err);
}
});
});
});
</script>
<form id= "Form1" runat= "Server" >
<input id= "btn" type= "button" value= "button"/>
</form>
Background code
Namespace WebApplication1
{
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
}
[WebMethod]
public static string Hello (String str)
{
return str + "1";
}
}
}
Successful execution, code or this can be put on vs2005 above try, welcome to ask questions, solve analysis.