Javascript Http post响应需要在本地存储中保存和检索

Javascript Http post响应需要在本地存储中保存和检索,javascript,arrays,json,angular,post,Javascript,Arrays,Json,Angular,Post,我的this.http.post给了我一个回复。下面是我的代码 this.http.post('http://funiks.com/adminv7/offline-api/login.php', {username: user_form_value,password: password_form_value}) .subscribe( (response)=> console.log(response) ); 我想通过在本地存储中使用类似这样的来保存响应,这是我在js中的

我的
this.http.post
给了我一个回复。下面是我的代码

this.http.post('http://funiks.com/adminv7/offline-api/login.php', {username: user_form_value,password: password_form_value})
  .subscribe(
    (response)=> console.log(response)
  );
我想通过在本地存储中使用类似这样的保存响应,这是我在js中的做法,但请指导我如何在angular中保存响应,以及将代码准确放置在何处-

 localStorage.setItem("getLoggedInUserANG",JSON.stringify(response));
请指导,类似地,如何在变量中返回结果在js中,我这样做,并从数据中获取用户名::

loggeduser_array  = JSON.parse(localStorage.getItem("getLoggedInUser"));
    console.log(loggeduser_array.username);
请参见以下控制台中的响应:

尝试以下代码向localstorage添加响应

.subscribe(
   response=>{
   localStorage.setItem("getLoggedInUserANG",JSON.stringify(response));
});

localStorage
不是js,而是HTML5的特性

   const headers = new Headers();
    headers.append('Content-Type', 'application/json');
  var loginDetail = {username: user_form_value,password: password_form_value};

this.http.post('http://funiks.com/adminv7/offline-api/login.php', JSON.stringify(loginDetail),{headers})
  .subscribe(
    (response)=>
localStorage.setItem("getLoggedInUserANG",JSON.stringify(response));
console.log(response);
  );
//  Just get local storage value where you need.
loggeduser_array  = localStorage.getItem("getLoggedInUser");
    console.log(loggeduser_array.data); // you stored promise as response so while get try like this.

这是我在js代码中得到的结果-,如何使用if success并在js中获取数据,如下-
$.ajax({url:'http://funiks.com/adminv7/offline-api/login.php,类型:'POST',内容类型:'application/json;charset=utf-8',数据类型:'json',数据:json.stringify(dict),}).done(函数(data,textStatus,jqXHR){if(data.status==“SUCCESS”){localStorage.setItem(“getLoggedInUser”,JSON.stringify(data.user));
但从角度看,我得到了这个-,如何得到类似的结果??使用
JSON.parse(response.\u body).user
由于响应主体是字符串而不是对象,但我不能仅保存我使用html5或js保存的内容,在angular中,我在本地存储中保存了很多不需要的内容,我只想保存与使用html5方法保存的内容类似的内容,请指导我如何操作angular始终使用
响应l类似于jquery中的
data
,这是我用js代码-pastebin.com/tb1dGA1f得到的结果,如何使用if success并像在js中那样获取data.user-$.ajax({url:,type:'POST',contentType:'application/json;charset=utf-8',dataType:'json',data:json.stringify dict),})。完成(函数(data,textStatus,jqXHR){if(data.status==“SUCCESS”){localStorage.setItem(“getLoggedInUser”),JSON.stringify(data.u‌​ser));但在angular中,我得到了这个-pastebin.com/W49NAQvz,如何得到类似的结果?我想你的API没有返回任何数据我附上了它返回的屏幕截图,我还附上了pastebin链接,你看到了吗?。再次为你附上-->angular-pastebin.com/W49NAQvz的结果,js-pastebin.com/tb1dGA1f的结果