js ajax url如何重定向,如何在ajax中重定向特定的url

I am validating a login form using ajax call. It is working great when you enter the wrong information. But if you enter the right credentials nothing happens. I am confused what to do? sample code:

我正在使用ajax調用驗證登錄表單。當你輸入錯誤的信息時,它工作得很好。但如果您輸入正確的憑證,則不會發生任何事情。我不知道該怎么辦?示例代碼:

$.ajax({

type: 'POST',

url: URL +'/foo/',

data: {'uname': name, 'password':pass},

success: function(data) {

if (data["success"] === "false") {

//show some message

$("#password").val("");

}

else {

// here i want to redirect to some url say, /bar/

I am confused how to do it.

},

dataType: "json",

});

return false

3 个解决方案

#1

3

you can use javascript.

您可以使用javascript。

location.href="new url";

it will take you to the new url

它將帶您到新的url

var querystringParam="sample";

var tempUrl="http://www.test.com?" + "variablettopass=" + querystringParam

location.href=tempUrl;

if you have more than one append to query string...

如果查詢字符串有多個附加項……

if you want your server name from browser window use this code

如果您希望您的服務器名稱從瀏覽器窗口使用此代碼。

window.location.hostname

but if you do location.href // it will take care...i just gave you for info

但是如果你選擇位置。href //它會小心的…我只是給你一些信息

#2

0

$(location).attr("href","url here")

#3

0

Try this:

試試這個:

window.location = url;

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值