0

The following ajax call works just fine in Chrome/FF, but is failing in IE only. I've tried turning cache off, physical/relative paths, async on and off, but not having any luck. I've been cruising around in SO all morning finding and testing different solutions, but I'm still not having any luck.

The error code returned isn't terribly helpful: error undefined

Any Ideas?

function CreateCard(//a bunch of paramaters//){



                var soapMessage ='//big long soap string goes here//';          
                var webServiceURL="//consumption URL (relative)";


                $.ajax({
                    url: webServiceURL, 
                    type: "POST",
                    crossDomain: true,
                    dataType: 'xml',
                    data: soapMessage, 
                    processData: false,
                    contentType: "text/xml; charset=\"utf-8\"",
                    success: function(data, status, req, xml, xmlHttpRequest, responseXML) { 
                        var newCardID=$(req.responseXML).find('AddeCardRequestResult').text();  //Fetches new card id
                        $('div#debug').html("success: " + newCardID)  
                        $('#CID').val(newCardID);

                        __doPostBack('btnSubmit', newCardID);

                    }, 
                    error: function(xhr, msg) { 
                        $('div#debug').html(msg + '\n' + xhr.responseText)
                    } 
                });




            }
sdowswell
  • 101
  • 12
  • Is `soapMessage` an object or a string? Is the `webServiceURL` expecting POST data? – MonkeyZeus Nov 14 '13 at 18:23
  • soapMessage is a string. Concatonated XML, really. I'll admit, I'm not familiar with SOAP, but since this works elsewhere I don't think there's anything wrong with the way that element is formatted. – sdowswell Nov 14 '13 at 18:26
  • Oh, just curious because I've never used it like that. Are you familiar with the Network tab of Chrome/FireFox/ or IE? – MonkeyZeus Nov 14 '13 at 18:28
  • I am pretty sure it wants POST. Just tried GET and received the same error. – sdowswell Nov 14 '13 at 18:28
  • What do you mean by `"//consumption URL (relative)"`? Specifically the `relative` part? Is this on your domain or a different domain? – MonkeyZeus Nov 14 '13 at 18:31
  • this is the url to the asmx file. it's a relative path, and the service is on the same domain. – sdowswell Nov 14 '13 at 18:34
  • 1
    Oh ok, that could be your issue because it probably makes `crossDomain: true,` unnecessary – MonkeyZeus Nov 14 '13 at 18:36
  • Removed cross domain, now getting a real live error! (which isn't awesome but better than nothing ;) ) -- it's aborting now due to "A potentially dangerous Request.QueryString value" – sdowswell Nov 14 '13 at 18:39
  • 1
    `data: soapMessage,` is probably causing it. Your AJAX is specifying a POST but you are sending a querystring appended to your URL since you are not passing an Object through `data: soapMessage,`. Do you have access to the ASMX file? What does the file want exactly? Also, are you familiar with the Network tab of Chrome/FireFox/ or IE? If not then which browser are you using? – MonkeyZeus Nov 14 '13 at 18:44
  • not familiar with the network tab, no. I don't have access to the ASMX, sadly. The file wants a set of values, strings and integers that the server then plugs into a database. I've never worked with SOAP before, so I'm not sure what I'm doing is in any way 'correct' – sdowswell Nov 14 '13 at 18:50
  • That's ok, there's a first time for everything. I can tell that you want to learn but if you want continued help then I would like to kindly request that you answer all of my questions when I ask them so that I do not have to keep on re-asking things. What browser are you using? – MonkeyZeus Nov 14 '13 at 18:56
  • sorry--there's a lot of questions and debugging and back and forth and so on. ;) the original error is limited to IE 8. Now that crossdomain is out, FF and Chrome are doing the same. – sdowswell Nov 14 '13 at 19:03
  • In Chrome, hit F12 and go to the Network tab. Now that you are on the Network tab you need to refresh the web page. and look for the call to your ASMX file and click on it. You'll see `Headers` `Preview` `Response` and some other goodies and the three I mentioned will be the most important to you. – MonkeyZeus Nov 14 '13 at 19:25
  • Geeze... just throw every parameter in the list in there!! What does the third parameter in the error callback contain? Is this a CORS request? If so, are you using a version of IE that supports CORS? It's very possible that IE is seeing the xml as invalid, which you would be able to see in the console, and it would throw a "parseerror" as the third parameter in the error callback. – Kevin B Nov 14 '13 at 19:39
  • Finally able to resolve now that I am getting decent feedback from the error handler. Thanks so much for your help @MonkeyZeus !! If you want to throw your note about crossdomain into an answer so i can credit you with the solution. – sdowswell Nov 14 '13 at 20:28
  • Done deal, thanks! Let me know if I can provide additional information in my answer for anyone landing on this page in the future. Or of course feel free to comment on it :) – MonkeyZeus Nov 14 '13 at 20:34

2 Answers2

0

With ie you'll need to append some kind of random parameter to your request.

I typically use something like (new Date()).getTime() as the value for a parameter name that is not used by the remote application.

This will trick ie into thinking it's a new request every time.

Edit: Found a similar question adding link.

This answer does a better job of explaining it than I do, it also has a jquery solution included. (copied from the linked answer so credit goes there.)

$.ajaxSetup({ cache: false });
Community
  • 1
  • 1
Diver
  • 1,568
  • 2
  • 17
  • 32
  • where would I add this random parameter? – sdowswell Nov 14 '13 at 18:19
  • I'm sure there's a better jquery way to do this but the quick and dirty way would be webServiceURL + "?random_parameter=" + (new Date()).getTime(); of course this assumes that your url doesnt already have parameters attached, if so change ? to & – Diver Nov 14 '13 at 18:24
  • changed url ref to 'url: webServiceURL + "?rnd=" + (new Date()).getTime(),' still no dice. – sdowswell Nov 14 '13 at 18:33
  • What's the value of webServiceURL? Does it already have a ?param= in it? – Diver Nov 14 '13 at 18:34
  • var webServiceURL="/eCardWS/Administrator.asmx"; so no, no other params – sdowswell Nov 14 '13 at 18:36
  • re: your edit --> I'd come across that earlier today, but no luck there. Thanks though! – sdowswell Nov 14 '13 at 18:54
0

This answer is here to simply highlight the end result of the comments in OP's question:

webServiceURL is on the same domain as the script so crossDomain: true, is unnecessary.

data: soapMessage, is probably also causing an issue because AJAX is specifying a POST but soapMessage is an XML string which gets converted to a querystring appended to the URL.

MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77
  • Once this was configured, all browsers were displaying the same error, which I was able to (eventually) resolve. (in this case, my soapMessage string had an element that included some HTML formatted content. I had to pre-encode that before concatenating into the string using encodeURIComponent(). Once that was done, everything worked swimmingly. – sdowswell Nov 14 '13 at 21:02