首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >jQuery如何重定向

jQuery如何重定向
EN

Stack Overflow用户
提问于 2014-03-30 01:22:49
回答 2查看 77关注 0票数 0

我尝试重定向到另一个页面,这取决于我在脚本的回调函数中收到的数据。

代码语言:javascript
运行
复制
jQuery("button.logInBtn").click(function(){     
    if(jQuery('#userName').val() == "" || jQuery('#password').val() == ""){
        alertify.error("Please enter User Name and Password");  
    }
    else{
        jQuery.post( jQuery("#loginForm").attr("action"), 
                 jQuery("#loginForm :input").serializeArray(),
                 function(data){
                        alertify.success(data);
                 });        
    }
    jQuery("#loginForm").submit(function(){
        return false;
    });

});

如何让这个脚本检查我在回调函数中接收到了哪些数据?然后根据我收到的数据进行重定向

EN

回答 2

Stack Overflow用户

发布于 2014-03-30 01:27:20

这就是你所需要的

代码语言:javascript
运行
复制
jQuery.post( jQuery("#loginForm").attr("action"), 
             jQuery("#loginForm :input").serializeArray(),
             function(data){
                 if(data=="something"){ // replace with your condition
                     document.location.href = "http://example.net"; //redirect to example.net
}); 
票数 0
EN

Stack Overflow用户

发布于 2014-03-30 01:28:02

您必须定义alertify.success(data)data是从ajax返回的内容。

然后,您可以使用window.location.href = 'http://example.com'重定向

定义alertify.data的一种快捷方法是:

代码语言:javascript
运行
复制
alertify = function() {
  return {
    success: function(data) {
      if (data.username) { //or any other condition
        window.location.href = ...
      };
    };
  };
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22734288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档