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!!!!
3 Answers 3
You are making AJAX request outside your domain. This is browser limitation and applies to all browsers.
1 Comment
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);
1 Comment
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:
- If you're in control of the server and your users can stick to recent versions of Firefox, Chrome, or a few others, you can use the new CORS standard. That doesn't work at all with versions of IE prior to IE8, and in IE8 it doesn't work with jQuery's ajax stuff because Microsoft decided to use a different object (
XDomainRequestinstead ofXMLHttpRequest). - Otherwise, you'll need a server-side proxy that you send the request to (obeying the SOP) and then have a server resource actually post to
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.)
2 Comments
http://schooprove.nl (not http://www.schoolprove.nl, not https://schoolprove.nl), it should have worked whether you have the full path or not. But relative paths are always preferred where possible. Since the answer wasn't any of the answers other people gave you, you can answer your own question. StackOverflow will let you accept the answer (marking your question "answered") after a couple of days.
http://schoolprove.nlor another domain?