我有這個簡單的ajax調用來觸發一個API來驗證登錄憑證。window.location行事怪異。它不重定向到指定的路徑
$('#loginForm').submit(function (e) {
e.preventDefault();
$.ajax({
url: baseURL + "agent/login",
type: 'post',
data: {login: $('#login').val(), password: $('#password').val()},
success: function (results) {
if(results.status === 0){
window.location = baseURL + "agent/dashboard";
}
else{
alert(results.message);
}
},
error: function(data) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
});
});
現在完整的目標網址是localhost/app/agent/login
。 baseURL = http://localhost/app/
。
我正在服務器上接收請求。但是,當我回應背window.location
不會重定向我localhost/app/agent/dashboard
而它重定向到http://localhost/app/agent/localhost/app/agent/login
我不明白爲什麼會這樣。這裏是我的.htaccess
如果它可以幫助
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
我使用笨3.1.4 XAMPP
你確定'baseURL ==='http:// localhost/app /''?你有沒有嘗試只註銷'baseURL'來確認它是什麼? –
如果您只是嘗試在地址欄中輸入URL「http:// localhost/app/agent/dashboard」,會發生什麼? – CD001
儘管所有的答案,它的解決問題的評論。原來在'dashboard'上有一個不好的重定向。有時候,這種簡單的基本調試實踐確實有幫助。謝謝! – eNeMetcH