Jquery ajax call to use WebMethod from external js file

$.ajax(
   {
       type: "POST",
       url: "Default.aspx/GetAge",
       data: "{}",
       contentType: "application/json; charset=uft-8",
       dataType: "json",
       success: function (rsp) { SetAge(rsp); },
       error: function (rsp)
       {
           alert(rsp); 
       }
   });

Now he is reporting the following error: "Unable to find resource." I believe the URL is incorrect. This javascript is in an external file located in the same directory as Default.aspx ... any thoughts?

0
source share
1 answer

I believe your URL is incorrect - you are using a relative URL and they are processed by the browser relative to the current page. It is not considered relative to the js file. For example, if you are trying to execute this request from a message page www.xyz.com/SomeFolder/page1.aspx, then your ajax request will be redirected to www.xyz.com/SomeFolder/Default.aspx/GetAge, so configure the URL accordingly.

, URL- , /services/Default.aspx/GetPage - - <your domain>/services/Default.aspx/GetPage , .

0

All Articles