. Net+ajax invoke the JQuery backend method to implement the drawings

Source: Internet
Author: User

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.

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.