WebMethod (sometimes) returns entire website
I have a WebMethod which accepts one parameter.
When I send a request to the webmethod without any parameters everything works well but when I supply a parameter to the same method, it returns entire site instead of a string.
The page parameter changes nothing except the content of the list.
List is just ListView which displays list of strings.
When I use URLRewriting the URL is different in开发者_JAVA技巧 instances that I supply a parameter from instances when I do not.
Can anybody help me with this problem?
My WebMethod:
[WebMethod]
public static string GetResult(int id)
{
return "Hooray";
}
My web method call:
PageMethods.GetResult(docId,
function onSuccess(list) {
$(element).parent().siblings().filter(":first").append(list);
});
URL without parameter:
www.mywebsite.com/items is rewritten to www.mywebsite.com/items.aspx
URL with parameter:
www.mywebsite.com/items/1 is rewritten to www.mywebsite.com/items.aspx?id=1
Here's a discussion about your same issue that might shed some light on the situation. Basically, what it says is that it's not working because the handler that deals with PageMethods is looking for {pagename.aspx}/{methodname}, and your url rewriting is causing it to not recognize you are calling a page method.
One suggestion on that page was to add the following in your javascript code somewhere after the auto-generated call of the same signature:
PageMethods.set_path('/items.aspx');
This will make it call your page method using the real url instead of the rewritten one.
精彩评论