Problem - Ajax call on IE only works when another page with the same Ajax call is open in the browser

江枫思渺然 提交于 2019-12-23 05:59:43

问题


I am trying to have a POST Ajax call to a serverside API from SharePoint Content editor. The API returns list of URL and Title. Then the URL is added dynamically into the SharePoint List View. This works fine in Chrome but not on IE. I am getting XMLHttpRequest: Network Error 0x2ef3, could not complete the operation due to error 00002ef3

I created a test HTML with the Ajax call on my local and it works fine. The strange think is it works fine on the SharePoint page on IE if I had the local HTML file opened on the same browser. Can someone help me fix it?

Here is the AJAX call:

var response;
Var settings = {
“async”: true,
“crossDomain”:true,
“url”: url1,
“method”: “POST”,
“type”:”POST”,
“dataType”:”json”,
“Keep-Alive”:”timeout=0, max=1000”,
“Cache-Control”:”no-cache, no-store, must-revalidate”,
“Pragma”:”no-cache”,
“Expires”:”0”,
“headers”:{
“Content-Type”:”application/json; charset=utf-8”,
“api_key”:key1,
“Authorization”:”Bearer “ + tkn1
},
“complete”:function(text){
response=text.responseText;
},
“cache”:false,
“processData”: false,
“data”:data1()
};

function data1(){
return JSON.stringify(data2);
}

jQuery.support.cors=true;
$.ajax(settings).complete(function(){
var resObj=JSON.parse(response);
.....
});

回答1:


Keeping in mind that "it works fine on the SharePoint page on IE if I had the local HTML file opened on the same browser." Back tracked with trail and error and found that the Ajax Call works if both method:POST and type:POST are in the second Ajax Call with first Ajax call just with method: POST without type: POST

I am not sure why and how it works, but it does.

I guess IE somehow takes up cache data and cache:false along with Pragma: no-cache and Expires: 0 never seems to work.

Here is the complete solution:

var successSettings = {
    "async": true,
    "crossDomain": true,
    "url": url1,
    "method": "POST",
    "type": "POST",
    "dataType":"json",
    "Pragma": "no-cache",
    "Expires": "0",
    "headers": {
        "Content-Type": "application/json; charset=utf-8",
        "Authorization": tkn
        "api_key":key1
     },
     "success": function(text1){
         response = text.objlink;
     },
     "error": function(jqXHR, exception){
         var errorHandle = jqXHR + exception;
     },
     "cache": false,
     "processData": false,
     "data": dataSend()
};
var failSettings = {
    "async": true,
    "crossDomain": true,
    "url": url1,
    "method": "POST",
    "dataType":"json",
    "Pragma": "no-cache",
    "Expires": "0",
    "headers": {
        "Content-Type": "application/json; charset=utf-8",
        "Authorization": tkn
        "api_key":key1
     },
     "success": function(text1){
         response = text.objlink;
     },
     "error": function(jqXHR, exception){
        $.ajax(SuccessSettings).done(function () {
               var resObj = response;
               ....
        });
     },
     "cache": false,
     "processData": false,
     "data": dataSend()
};
jQuery.support.cors = true;
$.ajaxSetup({cache: false});
$.ajax(failSettings).done(function () {
     var resObj = response;
     ....
});


来源:https://stackoverflow.com/questions/53542060/problem-ajax-call-on-ie-only-works-when-another-page-with-the-same-ajax-call-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!