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);
.....
});
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
andtype:POST
are in the second Ajax Call with first Ajax call just withmethod: POST
withouttype: 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 withPragma: no-cache
andExpires: 0
never seems to work.Here is the complete solution: