11

I have a script that makes an ajax request to a remote server, that returns a plain text response. It works fine in all browsers except IE8 (shocker).

Here's the code:

$.ajax({
  url: 'abc.com/?somerequest=somevalue',
  cache: false,
  type: 'POST',
  data:{
    sub: 'uploadprogress',
    uploadid: this.uploadId
  },
  dataType: 'html',
  success: this.uploadProgressResp,
  error: this.errorResp
});

In IE8, it returns a "No Transport" error. I suppose it's because IE8 doesn't allow cross domain requests?

NOTE: I didn't write the API for the remote server. If I did, I would return JSON response rather than a plain text response. So yes, the dataType is supposed to be HTML rather than JSON.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • @PeterCPWong: yes but the reason is cross domain policy. so solution is same. – Chamika Sandamal Feb 17 '12 at 03:06
  • @ChamikaSandamal Actually the post you pointed to solved my problem. Using XDR for IE solved the problem for cross domain requests. –  Feb 17 '12 at 08:05
  • 2
    Please do not vandalize your posts. By posting on the Stack Exchange network, you've granted a non-revocable right for SE to distribute that content (under the [CC BY-SA 3.0 license](https://creativecommons.org/licenses/by-sa/3.0/)). By SE policy, any vandalism will be reverted. – Wai Ha Lee Feb 26 '19 at 15:37

2 Answers2

7

Try adding this somewhere before the ajax call - Best place for it is before any other JavaScript executes!

jQuery.support.cors = true;

Without this, the "No transport" error will be thrown by Internet Explorer. The error message itself is rather confusing, but by default cross-domain ajax requests are blocked by IE, but do not appear to be so by other browsers - or at least, Chrome and Firefox will function to that effect.

I shared your pain on this one, historically. Quite confident that it will sort your issue.

SpaceBison
  • 3,704
  • 1
  • 30
  • 44
  • 2
    That surprises me - I had the "No Transport" issue and solved it immediately with that code. I did a bit more digging around and came across this: http://stackoverflow.com/questions/5087549/access-denied-to-jquery-script-on-ie - any help? Sorry my suggestion didn't work for you :\ – SpaceBison Feb 16 '12 at 20:06
  • I had this issue, Worked in Chrome but give no transport error in IE, SpaceBison 's solution solved my problem. I had to place the call directly above the ajax call. I 1st tried adding it in $(document).ready but it didn't work and then i added it directly in front of the ajax call and it worked. Thanks SpaceBison – Lismore Jun 28 '12 at 14:21
  • Why everybody (me too) spends like 3 days to solve cross domain issues with ajax, when a simple line of code can solve this hell in 30 secondes. Why this answer doesn't come in first place when googling "jQuery enable cross domain". Thank you @SpaceBison ! – TCHdvlp Nov 20 '13 at 10:04
0

I know this is very old question, but sadly people still using IE8/9 and sometimes we have to support them :/

This is best solution I was able to find for this issue:

https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest

Just include following script in your html and that's it, you don't have to modify anything in your jQuery request

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.3/jquery.xdomainrequest.min.js"></script>

Limitations:

  • IE6/7 isn't supported, only IE8 and IE9
  • Minimum jQuery version is 1.5
  • When using POST method in IE8/9, Content-Type header always will be set to text/plain
  • Current website and requested URL both must be using same protocol (HTTP->HTTPS or HTTPS->HTTP requests will not work)
Nicolo
  • 1,600
  • 2
  • 16
  • 18