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: (changes highlighted in blue)
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 ;)
Haha, nice and simple
Good job! :)
So, how long did it take to track that down?
I can't wait to see the new secret project!!!
-Mike
Longer than it should have :)
Yeah, took about an hour I guess... most of which, I spent figuring out the ins-and-outs of Google Chrome's debugging tools ;)
I can't wait for the secret project to launch either... getting so close now :)
Not bad.
Hey, one hour isn't too bad. (Esp. if you're using unfamiliar tools).
Feel free to ask me to do a private beta test if you want. ;)
-Mike
hello
very good articles thanks....evden eve nakliyat evden eve nakliyat
Thanks
This is very helpful. Thanks!
Your third line in both the before and after code seems to be cut short.
Diwant
Fixed
Oops... yep, a common (for me) cut-and-paste from nano with text-wrapping off ;)
All fixed now.
Post new comment