Note that there are some explanatory texts on larger screens.

plurals
  1. POError callback every time when trying to POST XML using jQuery in non-IE browsers
    text
    copied!<p>I am trying to communicate with Google's spell check service using jQuery. Google's service requires that you post XML and it will in turn return an XML response. In IE, the success callback gets hit every time, but in non-IE browsers (tested in Firefox and Chrome) the error callback is getting hit every time.</p> <p>The biggest difference is in how the XML that is posted is created. For IE, an ActiveX object is getting created; for all other browsers the DOMParser is used (example from <a href="http://www.w3schools.com/Dom/dom_parser.asp" rel="nofollow noreferrer">w3schools</a>).</p> <p>Below is my test code (NOTE: 'spell-check' represents the ID of an HTML button.) What am I missing or need to change to successfully post XML from jQuery across browsers?</p> <pre><code>&lt;script type="text/javascript"&gt; var xmlString = '&lt;?xml version="1.0"?&gt;&lt;spellrequest&gt;&lt;text&gt;mispell&lt;/text&gt;&lt;/spellrequest&gt;'; function createXMLDocument(s) { var xmlDoc; if (window.DOMParser) { var parser = new DOMParser(); xmlDoc = parser.parseFromString(s, 'text/xml'); } else { xmlDoc = new ActiveXObject('Microsoft.XMLDOM'); xmlDoc.async = 'false'; xmlDoc.loadXML(s); } return xmlDoc; } $(function() { $('#spell-check').live('click', function(e) { e.preventDefault(); $.ajax({ cache: false, contentType: 'text/xml', data: createXMLDocument(xmlString), dataType: 'xml', processData: false, type: 'POST', url: 'https://www.google.com/tbproxy/spell?lang=en', success: function(data, textStatus, XMLHttpRequest) { alert(textStatus); //debugger; }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); //debugger; } }); }); }); </code></pre> <p></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