Ok this problem is starting to get annoying!
I have this jquery ajax request code:
$.ajax({
type: "GET",
url: "/nameCheck.php",
data: {addressName: ""+addressName+"", customer: customer},
success: TEST,
error: reportProblem
});
the nameCheck.php looks like this:
include_once("db_connect.php3");
$addressName = $_GET["addressName"];
$customer = $_GET["customer"];
$search = mysql_query("select count(*) from Address where AddressName=".quote_correct($addressName)." and CustomerNumber=$customer",$database);
$rows=mysql_fetch_array($search);
$number_of_rows = $rows[0];
// note quote_correct is just a function to clean up the users input
if ($number_of_rows>1)
{
$message ="NO";
}
else
{
$message ="OK";
}
echo $message;
?>
and on success the TEST function looks like this
function TEST(data,status){
alert(data+" - "+ status);
}
Through a log file I set up in the php code - I see the process of checking to see if the customer name exists is working and I get the proper response of OK or NO.
The ajax call is a success too - and the TEST function is called 开发者_开发百科- but no data is present..
Does anyone know why this isn't working?
Try having your ajax call look like this:
$.ajax({
type: "GET",
url: "/nameCheck.php",
data: { addressName: "" + addressName + "", customer: customer },
success: function (data) {
alert(data);
},
error: function(xhr, status, error) {
}
});
I usually also state in my get/post calls the return type. (json,html...) and does the returning php function know what to return?
You need to set the content-type header in your PHP. The default response is txt/html, jQuery wants JSON.
header('Content-type: application/json');
精彩评论