Patching jqSOAPClient for Google Chrome
We've been using jQuery at work for an up-coming secret project, and frankly, I think it's great!! :) We've also been using the excellent jqSOAPClient plugin for performing SOAP requests. However, when Google Chrome was released last month, I immediately tried our app with the new browser, only to find that all jqSOAPClient requests were failing under Chrome :(
Well, I left it for a couple of weeks - hoping that the jQuery and/or jqSOAPClient developers would already be aware of the issue, and would get time to fix it pretty quickly. But unfortunately, that has not been the case (or at least not that I can tell) - and I'm in no way complaining. So today I decided to have a go a tracking down the issue myself.
Well, I found it... in short, it seems that if you set an invalid (ie empty / undefined
) request header on an
XMLHttpRequest
object, then Chrome silently fails - specifically, it
reports no errors, but does not make any attempt to send the HTTP request at all.
Anyway, the solution is to add an empty/undefined
check to the beforeSend
function set in the
SOAPClient.SendRequest()
function. So, the jqSOAPClient code that looks like this:
beforeSend: function(req) {
req.setRequestHeader("Method", "POST");
req.setRequestHeader("Content-Length", SOAPClient.ContentLength);
req.setRequestHeader("Content-Type", SOAPClient.ContentType + "; charset=\"" + SOAPClient.CharSet + SOAPClient.CharSet + "\"");
req.setRequestHeader("SOAPServer", SOAPClient.SOAPServer);
req.setRequestHeader("SOAPAction", soapReq.Action);
}
becomes this:
beforeSend: function(req) {
req.setRequestHeader("Method", "POST");
req.setRequestHeader("Content-Length", SOAPClient.ContentLength);
req.setRequestHeader("Content-Type", SOAPClient.ContentType + "; charset=\"" + SOAPClient.CharSet + SOAPClient.CharSet + "\"");
if ((SOAPClient.SOAPServer!=undefined)&&(SOAPClient.SOAPServer.length>0))
req.setRequestHeader("SOAPServer", SOAPClient.SOAPServer);
if ((soapReq.Action!=undefined)&&(soapReq.Action.length>0))
req.setRequestHeader("SOAPAction", soapReq.Action);
}
Simple :)
And the result - Google Chrome now works very nicely with our new, secret project... hopefully more on that soon ;)
PS - I did check the latest jqSOAPClient beta, but it does not fix this specific issue. So I will, of course, suggest including this tweak to the jqSOAPClient developers :)