我有一個重定向一旦它檢索到XML的問題。它的登錄名可以獲取ID用戶名和ID密碼的值,並檢查它是否存在。在這種情況下,它顯示警告「工作」,但不重定向頁面,我不知道爲什麼。AJAX請求檢索XML輸出和案件重定向...但它不重定向
上點擊查詢功能去如下:
$(document).ready(function(){
$("#submit").click(function(){
login();
function login() {
$.ajax({
type: 'POST',
url: 'dt_login.php',
async: false,
cache: false,
data: {
params: {
op: 'authenticate',
username: $("#username").val(),
password: $("#password").val()
}
},
dataType: 'xml',
success: function(xml) {
switch($(xml).find('message').text()) {
case 'OK':
alert("worked");
window.location = 'http://www.newlocation.com';
break;
case 'DENIED':
alert("Incorrect username or password.");
break;
default:
alert("defualt");
break;
}
}
});
}
});
});
dt_login.php:
<?php
function api($params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://exampleurl.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$output = curl_exec($ch);
curl_close($ch);
print $output;
$xml = new SimpleXMLElement($output);
$_SESSION['user_id']= $xml->user_id;
}
if(is_array($_POST['params'])) { api($_POST['params']); }
?>
,輸出:150OK1111swatkinsSAM WATKINS
任何想法?它爲什麼顯示警報但不會重定向?
您是否在原始代碼中的語句之後缺少';'? – 2014-09-03 20:16:23
實際上他們之前有過,並刪除他們,看看它是否改變了任何東西。只更新了代碼。 @AndrewBarber – lancey 2014-09-03 20:18:01
看起來很奇怪,你沒有取消動作,除非你點擊的不是一個按鈕/鏈接/表單'$(「#submit」)。click(function(evt){evt.preventDeafult();' – epascarello 2014-09-03 20:19:52