Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX sending json data as text/xml
    text
    copied!<p>I have two sites using the same javascript code to interact with several web services. The code works perfectly in one site, but in the other, it is sending the data as text/xml. I have looked at the web config files in both sites and cannot spot anything that could cause the difference. The AjaxControlToolkit DLL files are the same. The AJAX call fails with an error 500 because the data is not in the proper form. </p> <p>Code that makes the AJAX call:</p> <pre><code>function displaySessionNotifications() { $.ajax({ type: "POST", async: false, url: "NotificationService.asmx/ListSessionNotifications", contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify({}), success: function (data) { $list = JSON.parse(data.d); if (window.console.log) { window.console.log('Notification Service Msg Cnt: ' + $list.length) }; for (var i = 0; i &lt; $list.length; i++) { displayMessage($list[i].MessageText, $list[i].MessageType, $list[i].IsSticky, $list[i].jGrowlClass, $list[i].ContainerId); }; if ($list.length &gt; 0) { clearSessionNotifications($list[0].SessionId); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert("NotificationService/ListSessionNotifications failed: " + XMLHttpRequest.responseText); } }); } </code></pre> <p>Watch Data from Firebug: </p> <p>this Object { url="NotificationService.asmx/ListSessionNotifications", global=true, type="POST", more...}</p> <pre><code>XMLHttpRequest Object { readyState=4, status=0, statusText="error"} errorThrown [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js :: &lt;TOP_LEVEL&gt; :: line 16" data: no] { name="NS_ERROR_FAILURE", message="Component returned fail...4005 (NS_ERROR_FAILURE)", result=2147500037, more...} textStatus "error" </code></pre> <p>Firebug console display of the code that works:</p> <pre><code>Server ASP.NET Development Server/10.0.0.0 Date Wed, 21 Sep 2011 17:44:39 GMT X-AspNet-Version 4.0.30319 Cache-Control private, max-age=0 Content-Type application/json; charset=utf-8 Content-Length 10 Connection Close Request Headers Host 127.0.0.1:54837 User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2 Accept application/json, text/javascript, */*; q=0.01 Accept-Language en-us,en;q=0.5 Accept-Encoding gzip, deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Connection keep-alive Content-Type application/json; charset=utf-8 x-requested-with XMLHttpRequest Referer http://127.0.0.1:54837/WebSite/TestNotifications.aspx Content-Length 2 Cookie JXID=80VR2F3uNRgK8YteuGgnAbsR; JXHID=false; Identifier=Id=20c8b636-7ec4-464f-b6dc-867d0924f475; enhanced=pass; Skin=Default; ASP.NET_SessionId=3nientky4k1hdy3gkfemne04; linkedin_oauth_BW-FUQKDybTn3R7TmZ-gHFmiFpzKY9ztqInF8jLVbHwNNkm_iSnIii26jEJts4wI_crc=null </code></pre> <p>Same data for code that fails:</p> <pre><code>Response Headersview source Server ASP.NET Development Server/10.0.0.0 Date Wed, 21 Sep 2011 18:34:01 GMT X-AspNet-Version 4.0.30319 Cache-Control private Content-Type text/html; charset=utf-8 Content-Length 4516 Connection Close Request Headersview source Host 127.0.0.1:60391 User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2 Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language en-us,en;q=0.5 Accept-Encoding gzip, deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Connection keep-alive Origin http://localhost:60391 Access-Control-Request-Me... POST Access-Control-Request-He... content-type,x-requested-with Pragma no-cache Cache-Control no-cache </code></pre>
 

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