私は自分のウェブサイトに大きなフォームを持ち、serialize()を使ってフォームを処理しています。jquery ajax json doesnt return true
私の問題は:
結果は常に偽フォームが完了した後に結果!私は火かき棒を使ってチェックした。 falseの場合、結果が表示されます。実際にはdata.ok == trueが呼び出されましたが、ページにメッセージが表示されませんでしたか?それは宛先アドレスにページをリダイレクトしませんでしたか?
jqueryのAJAX:PHPで
$("#details").live("submit", function(e){
var form = $(this).serialize();
var data_string = form;
$.ajax({
type: "post",
url: "../_include/ajax.php?details",
cache: false,
data: data_string,
dataType: "json",
success: function(data) {
if(data.ok) {
("#pop").html(data.message).addClass("oke").fadeIn("slow");
setInterval(function() {
location.href = data.redirect
},2000)
} else {
$("#pop").html(data.message).addClass("warning").fadeIn("slow");
}
}
});
e.preventDefault();
})
:
if (isset($_GET['details'])) {
if (empty($name)) {
$data['ok'] = false;
$data['message'] = 'Please enter name!';
} ................ {
.............
} else {
$db->query("UPDATE query....");
$data['ok'] = true;
$data['message'] = 'Your details has been submitted!';
$data['redirect'] = 'index.php?p=details';
}
echo json_encode($data);
}
あなたはdata.okを試してみました==本当ですか? – Colum