我有这个简单的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