Jquery Ajax Call does not Call the function in .CS file

后端 未结 3 1777
旧巷少年郎
旧巷少年郎 2021-01-26 02:27

Always i get the alert in the \"error\". When i debugged i get the type,url as undefined. can anyone help me why that method is not getting called??

$(document).         


        
相关标签:
3条回答
  • 2021-01-26 02:39

    Hi all i just used the jquery file hosted with google.

    It worked out fine.

    Previously i was using the jquery version 1.7.1 that i had downloaded and stored in my local. I also saw a lot of questions in the forum that this particular ajax call is quite not happening properly with .NET 4. I am not sure and forgive me if i am wrong but i do have a feeling that 1.7.1 in this case is not properly working with ASP.NET 4.

    P.S -> I used this in the script tag --> src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"

    0 讨论(0)
  • 2021-01-26 02:44

    The jquery Ajax method is going to post your data in json format using the plain html protocol. ASP.NET will be expecting to unwrap a SOAP request to pass to the webmethod. Thus the error. You should use an MVC action instead, as suggested in one of the comments. EDIT:On further investigation ASP.Net has an attribute that will allow the web method to be called: [System.Web.Script.Services.ScriptService]. Use this attribute on the class and it might solve your problem.

    0 讨论(0)
  • 2021-01-26 02:47

    If im correct you should be using static method for these purposes, so function in your code behind should look like this

    [WebMethod]
    public static void jQueryAjaxCalledMethod()
    {  
       //SOME CODE HERE       
    }
    

    If you still get some errors take a look on this guy blog Encosia maybe you'll find there a solution

    0 讨论(0)
提交回复
热议问题