我有一个Ajax / PHP代码,我想检查返回的文本是真还是假:
$(".gets").click(function() {
// some details
$.ajax({
type: "POST",
url: "step2.php",
data: dataString,
success: function(data) {
// This is the button to hide
$('.nums').fadeOut('fast');
} // end function
}); // end ajax
return false;
});
step2.php
if($num < 3) {
echo 'please choose at least 3 nums<br />';
$hideButton = false; // hide show nums button
} else {
$hideButton = true;
}
提前致谢
答案 0 :(得分:0)
你必须回复$hideButton
。该信息将在data
if($num < 3) {
echo 'please choose at least 3 nums<br />';
$hideButton = false; // hide show nums button
} else {
$hideButton = true;
}
echo $hideButton;
然后 -
$.ajax({
type: "POST",
url: "step2.php",
data: dataString,
success: function(data) { // data now has the value of $hideButton
if(data == 'true') {
// This is the button to hide
$('.nums').fadeOut('fast');
}
} // end function
}); // end ajax
答案 1 :(得分:0)
$(".gets").click(function() {
// some details
$.ajax({
type: "POST",
url: "step2.php",
data: dataString,
success: function(data) {
if(data == 'true')
{// your if code
}
else
{// your else code
}
// This is the button to hide
$('.nums').fadeOut('fast');
} // end function
}); // end ajax
return false;
});
答案 2 :(得分:0)
尝试更改下面的脚本。
在AJAX success
success: function(data) {
if(data == 'false'){
$('.nums').fadeOut('fast');
}else{
// other event if you want
}
在step2.php
echo ( $num < 3 ) ? 'false' : 'true';