我正在创建一个登录页面,我想在XHR发布请求成功后重定向到URL。
function statusChangeCallback(){
// if(response.status === 'connected'){
console.log('Logged in and authenticated', $("#username").val(), $("#password").val());
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
console.log(xhr.response)
$.cookie("access_token",JSON.parse(JSON.parse(xhr.response).data.user).token);
{
location.replace("https://localhost/executive.html");
}}
}
xhr.open("POST", "https://localhost/api/login", false);
xhr.send(JSON.stringify({ "password": $("#password").val(),"email":$("#username").val()}));
// $.cookie('accessToken', FB.getAuthResponse() .
我正在使用location.replace
,但无法正常工作。
xhr.response
的控制台输出:
{"error": false, "message": "User Data updated successfully", "data": {"user": "{\"_id\": \"5c274f4f4302725e08b839e6\", \"email\": \"demo@email.com\", \"password\": \"password\", \"token\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6ImRlbWL1iVVScLFN46Tczg\", \"facebook_accesstoken\": \"EAADlFlUKzwcBAM4WYk2pusO3J4PH92TUM3z9lEeHZCb15BegHqC97NH0aTsH7bN9JMfiKDoTQbExqIKze3SigaryZCU6v3dhTW2zZB4aqPuhopMWTQ3Y0gie85VkeYAwNEGRTmHgJ3dw7iH5CYMmuAZDZD\", \"facebook_email\": \"apexian2013_ashwani@yahoo.com\", \"instagram_password\": \"P********\", \"instagram_username\": \"p**********\"}"}, "errors": null, "code": 200}