sdowswell
sdowswell

Reputation: 101

Calling ASPX method from jquery AJAX

I'm trying to call a method in a seperate ASPX file with jQuery via AJAX. After running through a number of tutorials with the same basic procedure, I'm still having no luck.

Here's the markup

<input class="myButton">
<div id="debug"></div>

jquery

$(".myButton").click(function(e){       
    e.preventDefault();
    alert('go');   //this triggers just fine.



    $.ajax({
                     type: "POST",
                     url: "/functions.aspx/ServerSideMethod",
                     data: "{'param1': 'foo'}",
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     async: true,
                     cache: false,
                     success: function (msg) {
                         $('div#debug').text(msg.d); 
                     }
        });



});

and the ASP residing in my functions.aspx file (all of it, completely unedited)

[WebMethod]
public static string ServerSideMethod(string param1)
{
    return "Message from server with parameter:"+param1;
}

Currently, it seems to be connecting to the page alright. The error I'm getting is as follows:

Unknown web method ServerSideMethod. Parameter name: methodName

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Unknown web method ServerSideMethod. Parameter name: methodName

Upvotes: 0

Views: 183

Answers (1)

Vadim
Vadim

Reputation: 17957

Your url is likely not correct. If the page you are calling from is in the following place:

/a/b/yourpage.aspx

Your call is looking in the following place for your functions.aspx file

/a/b/functions.aspx

Ensure that the url path is correct.

Upvotes: 1

Related Questions