views:

99

answers:

1

I'm using ASP.net and I'm trying to execute a webmethod from jquery. I have the following file structure:

/MyWebService.asmx
/MyPage1.aspx (referencing a javascript file which calls a webmethod in MyWebService.asmx)
/MySubFolder/MyPage2.aspx (MyPage2.aspx referencing the same javascript file)

My problem is that MyPage1.aspx can call the webmethod in the web service but MyPage2.aspx can't. Any ideas why? It has to be related to the fact that MyPage2.aspx is in a subfolder. If I simply move MyPage2.aspx to the root it works.

I'm using jquery and the code in the javascript file looks like this:

$.ajax({
type: "POST",
url: "MyWebService.asmx/MyWebMethod",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg)
etc.

I've tried changing the url to: /MyWebService.asmx/MyWebMethod (with a slash in front of MyWebService) but it doesn't make any difference.

Thanks.

A: 

I think it's worth a try to pass the relative URL such as "../MyWebService.asmx/MyWebMethod".

Personally, I prefer to pass absolute URL's during AJAX hits.

Cerebrus
I've tried this including passing an absolute URL and it still does not work.
Anthony
Hmmm... perhaps you should try debugging the code and stepping into the JQuery code to see what it resolves to.
Cerebrus