Reputation: 1004
I have a strange problem with Jquery AJAX. I get the following message at Ie:
Acces denied. jquery-1.4.4.min.js
The code i run is:
$(document).ready(function(){
leuk(<?php echo $_POST['decrease_id']; ?>,<?php echo $_POST['user_id'] ?>);
var int=self.setInterval("leuk(<?php echo $_POST['decrease_id']; ?>,<?php echo $_POST['user_id'] ?>);",5000);
});
function leuk(decrease_id,user_id)
{
$.ajax({
type: "POST",
url: 'http://schoolprove.nl/nieuw/index.php/leerlingen/checkvoortgang/',
data: 'decrease_id='+decrease_id+'&user_id='+user_id,
success: function(msg){
$('#output').html(msg);
document.getElementById('opnieuw').style.display = 'none';
}
});
}
It is just a simple AJAX request but i don't know why this occured. I did this reqeust several times but this at this page this error always occured and the AJAX request does not work.
Does anybody know how to solve this.
Thank you very much!!!!
Upvotes: -1
Views: 98
Reputation: 1074038
If your document page isn't also being loaded from http://schoolprove.nl
, you're running into the Same Origin Policy restriction.
You have very few options if you want to POST
data cross-origin:
XDomainRequest
instead of XMLHttpRequest
).schoolprove.nl
(edit: Tim Cooper's given you a very basic example of that in PHP).You'd have more options with a GET
, including:
...but my guess is that a GET
isn't appropriate for what you're doing, as it isn't idempotent. (If it is, then that's what I'd do.)
Upvotes: 0
Reputation:
You cannot make AJAX requests that are to a different domain than the one the script is currently on. Perhaps you can make a script on your server which issues the cross-site request, if necessary.
An example of the script that would be on your server:
$curl_res = curl_init("http://schoolprove.nl/nieuw/index.php/leerlingen/checkvoortgang/");
curl_setopt($curl_res, CURLOPT_POST, true);
curl_setopt($curl_res, CURLOPT_POSTFIELDS, "decrease_id=" . $_POST[ 'decrease_id'] . "&user_id=" . $_POST['user_id']);
curl_exec($curl_res);
Upvotes: 1
Reputation: 395
You are making AJAX request outside your domain. This is browser limitation and applies to all browsers.
Upvotes: 1