PageMethod returns the entire page

Hi, we use jquery to send ajax requests, but each time we return the contents of the page. We are using the .NET Framework version 2

$.ajax({ type: "POST", url: "ajaxPage.aspx/testMethod", data: "{test:'test'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (result) { $("#span_result").html(result.d).fadeIn(); }, error: function (msg) { $("#span_result").hide(); } }); //ajaxPage.aspx.cs [System.Web.Services.WebMethod] public static string testMethod(string test) { return test; } 
+4
source share
2 answers

Do you have this in your web.config?

 <system.web> <httpModules> <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </httpModules> </system.web> 
+2
source

The ScriptModule proposed by SP is probably missing you.

One more thing: your data parameter is not valid. I do not think this will cause the problem that you are seeing right now, but it may start to cause an invalid JSON primitive error after fixing the current problem. Change it like this:

 data: '{"test":"test"}' 

Key names must always be quotation marks, and quotes around keys and JSON values ​​must be double quotes (although ASP.NET more forgives this last point).

0
source

All Articles