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 个解决方案

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 //它會小心的…我只是給你一些信息

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

Try this:

試試這個:

window.location = 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:我正...
在修改公司的老项目 ,遇到了一个问题,就是session失效的时候,在页面没有刷新的情况下,点击操作无效,查了一下,原因是 ajax 机制无法实现 重定向 ,查了很久的资料,现有一下解决方法(都是百度得来的,自己整理一下方便以后使用) 1. ajax 是默认就是不支持 重定向 的,它是局部刷新,不重新加载页面。 2.我的解决办法就是从前后端都做处理,项目 遇到 重定向 大多出现在拦截器或者过滤器 。在项目 我使...
//设置 ajax 请求结束后的执行动作 complete : function(XMLHttpRequest, textStatus) { // 通过XMLHttpRequest取得响应头,sessionstatus var sessi...
使用 ajax 请求数据 var link = 'https://player.vimeo.com/progressive_redirect/playback/696349232/rendition/360p?loc=external&oauth2_token_id=1027659655&signature=405ffb945893ad5f05c543d7665ded03ae2dba2a8b8851ecbb309f63803ad85a' var xhr = new XMLHttpRequ.
由 于此前很少写前端的代码(哈哈,不合格的程序员啊),最近项目 用到 js on作为系统间交互的手段,自然就伴随着众多 ajax 请求,随之而来的就是要解决 ajax 的跨域问题。本篇将讲述一个小白从遇到跨域不知道是跨域问题,到知道是跨域问题不知道如何解决,再到解决跨域问题,最后找到两种方法解决 ajax 跨域问题的全过程。 不知是跨域问题 起 因是这样的,为了复用,减少重复开发,单独开发了一个用户权限管...
一、 ajax 重定向 的问题。 默认 ajax 是不支持 重定向 的,因为 ajax 本身就是局部刷新,不重新加载页面的。如果需要用到 重定向 可以通过以下方法: 第一步:后端代码改造。 在后端(大部分情况都是拦截器) 判断是否需要 重定向 。 Eg:session过期判断,当判断session已经过期了,就先判断此次请求是否是 ajax 的请求。 String type =request.getHead
最近在做的一个前后端分离的一个项目,这就涉及到登录验证的问题。我用的是token加上filter。 1,前端请求登录的时候,用用户名和加上当前时间生成一个token,存入redis,然后返回给前端。 2,以后每次请求前端带上token,在filter里做验证。 3,判断token是否有效,有效则放行,无效则 重定向 到登录页面。 这就存在一个问题, ajax 请求返回的 js o
以前写response.sendRedirect("/login. js p");是成功的,今天用到 ajax 请求,发送给后台,希望直接跳转,发现无效,首先要深入了解 ajax 请求和response.sendRedirect的机制 response.sendRedirect的机制 这种方式是在客户端作的 重定向 处理。该方法通过修改HTTP协议的HEADER部分,对浏览器下达 重定向 指令的,让浏览器对...