Problem - Ajax call on IE only works when another

2019-06-13 20:29发布

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条回答
Explosion°爆炸
2楼-- · 2019-06-13 20:42

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;
     ....
});
查看更多
登录 后发表回答