我尝试重定向到另一个页面,这取决于我在脚本的回调函数中收到的数据。
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;
});
});
如何让这个脚本检查我在回调函数中接收到了哪些数据?然后根据我收到的数据进行重定向
发布于 2014-03-29 17:27:20
这就是你所需要的
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
});
发布于 2014-03-29 17:28:02
您必须定义alertify.success(data)
,data
是从ajax返回的内容。
然后,您可以使用window.location.href = 'http://example.com'
重定向
定义alertify.data
的一种快捷方法是:
alertify = function() {
return {
success: function(data) {
if (data.username) { //or any other condition
window.location.href = ...
};
};
};
};
https://stackoverflow.com/questions/22734288
复制相似问题