I'm trying to make a call to a php script who write cookie and I make the call with jquery (ajax) here is all my codes:
this is the code who can anyone use to make the call:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://www.mywebsite.com/generated.js"></script>
<div id="generated"></div>
for the file "generated.js", I make the ajax call:
$(document).ready(function(){
$.ajax({
url : "generated.php",
type : "POST",
data : "",
success : function(n){
$( "#generated" ).html( n ); }
});
});
and here is the "generated.php" where i create the cookie:
<?php setcookie("TestCookie", "test"); ?>
when i try to use the first code in a html file in the same directory as the other it's working, but when i try to use it in another server it doesn't work, and thanks to all of you
It's a cross domaine restriction i think, you can't call a page outside your domaine via ajax. a work around is to use CURL.
So your architecture should look's like :
Wish it can helps.