Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery 1.6.2 ajax request to aspx method always returns parsererror
    text
    copied!<p>Im ready to start pulling my hair out here. Trying to use jquery ajax request in Firefox to return simple string from method in my code behind. Regardless of what I try, I always get parsererror - unexpected character. I tried at least a dozen different variations based on demos Ive found online, none work.</p> <pre><code> $.ajax({ type: 'POST', url: '/Search/BasicSearch.aspx/sayHello', contentType: "application/json; charset=utf-8", dataType: "json", data: '{}', success: function (msg) { alert(msg.d); }, error: function (jqXHR, textStatus, errorThrown) { alert(textStatus + ' ' + errorThrown); } }); </code></pre> <p>--code behind method</p> <pre><code>[WebMethod] public static string sayHello() { return "hello world"; } </code></pre> <p>I have tried returning a properly formatted json string in this method, still didnt work.</p> <p>EDIT: I forgot to mention that this site will is running on .NET 2.0. After unsuccessfully trying Will's suggestion below to set the response format to JSON, I thought I would try a plain 'ol generic handler and see what happens. Sure enough, it worked.</p> <p>public class Handler1 : IHttpHandler {</p> <pre><code>public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; context.Response.Write("{\"\": \"hello world\"}"); } public bool IsReusable { get { return false; } } </code></pre> <p>}</p> <p>So I am assuming its an underlying issue with .NET 2.0 aspx pages??? I think all of the examples I have seen were using at least 3.0. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload