Search code examples
jqueryasp.netwebmethod

jQuery+WebMethod+UrlRewriting: how to distinguish parameter from server method name


My ASP.NET web site converts URLs like http://smth.com/player/1234 into request to "player" page with parameter id=1234

On the page I need to make a web-request to the 'GetData' method on this page. I would like to do the request using jQuery. All tutorials I've found (http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/, for instance) suggests to pass URL/method name in 'url' parameter of '$.ajax'

$.ajax({
  type: "POST",
  url: "PageName.aspx/MethodName", // in my case that will be ... what?
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // Do something interesting here.
  }
});

The problem is that if I specify "player/1234/GetData" then request will be done to "player" page, but ASP.NET won't call GetData method...

Should I implement custom logic on this page and call 'GetData' in order to execute web-request? If yes, how can I identify that request is done to the WebMethod?

Or I should provide 'plain' url in the way like http://smth.com/player.aspx?Id=1234/GetData

I probably miss something? May be jquery does allow specify 'method name' in a separate field? Or I should configure my web site to handle that properly?

Please advise. Any ideas are welcome!


Solution

  • Dunno how to resolve the problem.. so instead I'm making request to web service (URL contains .asmx that bypass URL rewriting)...

    If you know how to resolve the original problem - please advise!