简体   繁体   中英

how to specify dataType in XDR request?

i am using XDR for cross domain resource sharing in ie. It works perfectly. I need to know how to specify the return dataType in this. I need to get json as responseText. Here is my code,

        if (window.XDomainRequest&& $.browser.msie && $.browser.version < 10) {
        xdr = new XDomainRequest();
        if (xdr) {
            xdr.onload = function () {
                var customResponse = xdr.responseText;

                }
            };
            xdr.open("get", url);
            xdr.send();
        }

Try this one

 xdr.onload = function () {
               var data = $.parseJSON(xdr.responseText);

                }

Unfortunately, XDR does not support setRequestHeader ( MSDN shows XDR has a really poor abilities), so you can't tell server you want JSON with Accept request header. But you can provide query string parameter that will tell server this info ( url += "?format=json" ). Of course, server must react on this param, otherwise it will make no sense. If you maintain your server for yourself, it will be easy task. If not, check if your API documentation allows you to request different content-types. If answer is no for both options, you probably should fallback to JSONp instead of XDR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM