Call ASP.NET PageMethod/WebMethod with jQuery - returns whole page

后端 未结 8 1077
北荒
北荒 2020-11-27 02:57

jQuery 1.3.2, ASP.NET 2.0. Making an AJAX call to a PageMethod (WebMethod) returns the full/whole page instead of just the response. A breakpoint on the page method shows

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 03:16

    Throwing this out here as a side note. I was getting that error due to the length of my string variables in my HTML string and the website I used to get my ajax called looked like this.

    loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "Default.aspx" : loc;
            $.ajax({
                type: "POST",
                url: loc + "/" + methodName,
                data: "{" + args + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: onSuccess,
                error: onFail
            });
    

    It wasn't capable of extracting the .aspx link correctly, so I just hardcoded my webpage instead of using the loc var.

提交回复
热议问题