XDomainRequest problem

て烟熏妆下的殇ゞ 提交于 2019-12-05 05:12:37

Are you sure that the service is sending a Access-Control-Allow-Origin-header matching the requesting URL?

Your problem may be the content-type sent, because XDomainRequest only support "text/plain".

Reference: http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

Cheers,

Andre Pedroso

A year old post,, you still there GiaNU?! You are calling xdr.onsuccess but I don't think that method exists. The xdr.onload works and seem to be equivalent to jQuery's AJAX "success" function.

This X-Domain stuff is quite new but there is a very nice working model available from MS now here: AJAX - Introducing Cross-domain Request (XDR)

The xdr.ontimeout I can't get to do a thing, but don't find a need yet :) I got things up and running first w/jQuery and now with ie9 thank's to the MS post.

The XDR has some trouble with the timing for my current application and is just used a timeout to handle it:

xdr.onload = setTimeout( function(){ doIt( xdr.responseText ), 2000});

Another gotcha is if you're running the service via Cassini then the "Access-Control-Allow-Origin" header won't be returned as Cassini doesn't recognise this. We had a scenario where our service calls were working on a test server but not working locally. Turns out the service was hosted in Cassini on our local dev machine but hosted on IIS on the test server.

Also here's the web.config setting for anyone that needs it (note: this allows access from any domain - "*"):

  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!