0
$.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); 
       }
   });

Right now it reports the following error: "Cannot locate the resource". I figure that I am specifying the url incorrectly. This javascript is in an external file located in the same directory as Default.aspx ... any thoughts?

6
  • 2
    Is an HTTP request actually being made? Try using Fiddler to see the precise URL being requested. If you've not used Fiddler before, this article is a good introduction - 4guysfromrolla.com/webtech/111208-1.shtml Commented Mar 8, 2011 at 4:00
  • @scott mitchell +1 for useful debugging tool! I am a moron, I needed to clean my build and rebuild. Commented Mar 8, 2011 at 4:05
  • 1
    Besides Fiddler Firebug is also wonderful tool. Commented Mar 8, 2011 at 4:08
  • 1
    It sound's like this is not a jQuery problem and maybe a problem with how your WebMethod is setup, encosia.com/2008/05/29/… might be helpful for you Commented Mar 8, 2011 at 4:08
  • Oops looks like you answered this before I posted, glad you got it working. Commented Mar 8, 2011 at 4:09

1 Answer 1

0

I believe that your URL is incorrect - you are using relative url and they are treated by browser as relative to current page. It is not considered relative to js file. For example, if your are trying this request from a page at say www.xyz.com/SomeFolder/page1.aspx then your ajax request would get directed to www.xyz.com/SomeFolder/Default.aspx/GetAge so adjust the url accordingly.

If possible, use urls in form such as /services/Default.aspx/GetPage - note leading slash - they will be always get translated into <your domain>/services/Default.aspx/GetPage irrespective of page from which you are invoking them..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.