Different AJAX result from different machines (simple code)
I have this jQuery AJAX and PHP code:
jQuery AJAX:
$.ajax({
type: "post",
url: "ajax/registration1.php",
dataType: "text",
success: function(request){
if (request == "success")
alert("registration1.php returns 'success'");
else
alert("registration1.php returns 'error'");
}
});
PHP:
<?php
echo "success";
?>
It works fine on my localhost, returns "registration1.php returns 'success'", but not on the other machine which returns 'error'.
Any ideas what I should check? Thanks.
FIXED:
He fixed the problem:
PHP is not being invoked when calling "registration1.php" directly, which causes the ajax() call to fail. If I wrap th开发者_运维技巧e form inside the Drupal framework, it appears to go through correctly.
I don't know why PHP was not being invoked though.
Thanks for the replies :)
make sure you put
header('Access-Control-Allow-Origin: *');
in your php file
<?php
header('Access-Control-Allow-Origin: *');
echo "success";
?>
do ajx request like
$.ajax({
type: "post",
url: "ajax/registration1.php",
dataType: "text",
crossDomain:true;
success: function(request){
if (request == "success")
alert("registration1.php returns 'success'");
else
alert("registration1.php returns 'error'");
},
error:function(jxhr,resp){
alert(jxhr.status);
alert(jxhr.responseText);
}
});
I would say there is a problem with your path.
Check the path is correct. And then check it again, cos it's not.
精彩评论