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.
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 w3schools).
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?
<script type="text/javascript">
var xmlString = '<?xml version="1.0"?><spellrequest><text>mispell</text></spellrequest>';
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;
}
});
});
});