簡體   English   中英

location.href無法正常工作

[英]location.href not working

我在早期使用過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)

阿賈克斯:

if (data.message == 'success') {
window.location.href = data.redirect;
return false;
}else if(){
etc...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM