1
在阿賈克斯成功功能不起作用我有一個登錄表單顯示在對話框中的jQuery 我需要從PHP傳遞變量來使用Ajax & JSON方法我的jQuery 問題是,在阿賈克斯成功的功能不工作,我總是得到誤差函數當使用JSON
這裏是我的PHP和jQuery代碼:
的Jquery:
$(document).ready(function() {
$(".logbut").click(
function() {
$(".login").dialog({
width: 400,
height:320,
modal: true,
autoOpen: true,
resizable: false,
show: {
effect: "blind",
duration: 3000
},
hide: {
effect: "drop",
duration: 1000
},
buttons: {
'login': function() {
$.ajax({
url:"login.php",
type: 'POST',
dataType:"json",
success: function(data) {
if(data.status == 'success'){
alert("Thank you for subscribing!");
}else if(data.status == 'error'){
alert("Error on query!");
}
},
error: function(){
alert("the ajax doesnt work");
}
})
}
}
})
})
});
的login.php:
<?php
$serverName = "AMIN-PC";
$connectionInfo = array("Database"=>"Market");
$conn = new PDO("sqlsrv:Server=AMIN-PC;Database=Market");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$response_array = array();
if($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
$passorg = $_REQUEST['passorg'];
$passorg = $conn->quote($passorg);
$userorg = $_REQUEST['userorg'];
$userorg = $conn->quote($userorg);
$sql = "select count(*) from customers
where customers_user=$userorg
and customers_pass=$passorg";
$stmt = $conn->query($sql);
$result = $stmt->fetch();
$count = $result[0];
if($count >0) {
$response_array['status'] = 'success';
}
else{
$response_array['status'] = 'error';
}
header('Content-type: application/json');
echo json_encode($response_array);
?>
HTML:
<div class="logbut">Login</div>
<div class="login" style="display:none;">
<form method="post" class="logform" action="login.php">
<input type="text" name="userorg" style=" width:80px;" class="userorg" />
<label>Username</label>
<input type="password" name="passorg" style=" width:80px;" class="passorg"/>
<label>Password</label>
<input type="submit" style="display:none" value="check"/>
</form>
</div>
感謝
顯示您在ajax中的錯誤回覆 – Saty
您應該檢查控制檯中的確切響應,也許還有其他輸出,如BOM。 – jeroen