Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript location.href不工作_Javascript_Jquery - Fatal编程技术网

Javascript location.href不工作

Javascript location.href不工作,javascript,jquery,Javascript,Jquery,我以前使用过location.href,但现在它没有重定向到页面。这是我的密码 function AuthenticateUserWithPage() { var UId = $('#amwayId').val();//username var UPw = $('#amwayPw').val();//password var ischecked = $('#idSave').is(':checked');// check remember me checkbox status if (UId

我以前使用过location.href,但现在它没有重定向到页面。这是我的密码

function AuthenticateUserWithPage() {
var UId = $('#amwayId').val();//username
var UPw = $('#amwayPw').val();//password
var ischecked = $('#idSave').is(':checked');// check remember me checkbox status

if (UId != '' && UPw != '') {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "../KPPRMobService/PNBMobWebService.asmx/IsValidUserWithPage",
        data: JSON.stringify({ username: UId, password: UPw, ischecked: ischecked }),
        async: false,
        success: function (data) {
            var obj = data.d;
            if (obj != "FALSE") {
                var targetUrl = "http://" + window.location.host + obj;
                window.location.href = targetUrl;
                //window.location.replace(targetUrl);
                return false;
            }
            else {
                $('#amwayId').val('');
                //if username or password is invalid
                alert("Please check your ID or password. The ID is not registered or the ID/ password is wrong.");
            }
        },
        error: function (result) {
            //if error occured.
            $('#amwayId').val('');
            alert("You cannot log in. Contact support center for further inquiries..");
        }
    });

}
else {
    //if username or password is null
    alert("Please enter ID/ password.");
    return false;
}
}

我使用此链接作为参考:。提前感谢。

Php:

 $form_data = array();
 $form_data['message'] = "success";
 $form_data['redirect'] = "http://www.example.com/example";
 echo json_encode($form_data)
阿贾克斯:


您的
窗口.location.href
没有明显的问题,问题出在其他地方。
obj
的值是多少?您的控制台中有没有错误?您是否尝试过使用location.assign?您确定您的测试在成功处理程序中达到if(obj!=“FALSE”){}块?
if (data.message == 'success') {
window.location.href = data.redirect;
return false;
}else if(){
etc...
}