Instead of $.ajax() use this custom code:
function newpostReq(url,callBack) { var xmlhttp; if (window.XDomainRequest) { xmlhttp=new XDomainRequest(); xmlhttp.onload = function(){callBack(xmlhttp.responseText)}; } else if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest(); else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) callBack(xmlhttp.responseText); } xmlhttp.open("GET",url,true); xmlhttp.send(); }
Note: this works for GET requests.
To configure it for POST requests, change the following lines:
function newpostReq(url,callBack,data)
data is the URL-encoded parameters of mail requests, such as: key1 = value1 & key2 = value% 20two
xmlhttp.open("POST",url,true); try{xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");}catch(e){} xmlhttp.send(data);
To summarize, open the connection as a POST request (line 1), set the request header for the urlencoded type of mail data (wrap it with try-catch for exceptional browsers) (line 2), then send the data (line 3).
source share