I recently transferred a website (from the same host, just a couple of folders down) and now my ajax script stopped working.
I get the following error for each script that needs to be loaded:
XMLHttpRequest cannot load http://www.website.nl/includes/loadmore.php. Response for preflight is invalid (redirect)
What could be causing this? This is my ajax script:
(function(){
/*
Meer websites laden
*/
var limit = 3;
var offset = 0;
var i =0;
$('#loadmore').click(function() {
limit = 3;
limit = 4;
if(i == 0) {
offset += 3;
} else {
offset += 4;
}
i++;
ajax();
});
var posts = document.getElementById('loadnews');
function ajax() {
$.ajax({
url: 'includes/loadmore.php',
type: "POST",
data: {limit: limit, offset: offset},
success: function(data){
var newWrapper = document.createElement('div')
//add class to newWrapper or whatever
newWrapper.innerHTML=data;
loadnews.appendChild(newWrapper);
},
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.
Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.
' + jqXHR.responseText);
}
}
});
}
ajax();
}());
I read something on changing the headers that are sent and allowing cross access, but I already do that in my htaccess file. It also doesn't really make sense to me since the files are still on the same host, just a different folder.
Like so:
#Cross site access toestaan
Header set Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"