简体   繁体   中英

Angular save vars to laravel session with ajax call dont work

I want to save some var to my session, and when i make the request with ajax this dont work. This is the service:

function HuntService( $http ) {
  this.hunts= {
    draws  : null,
    hunters: null
  };

  this.saveToSession = function( hunts) {
   var hunts = this.hunts;
    return $http.post('saveToSession', {
      hunts: hunts
    });
  };

}

HuntService.$inject = ['$http'];
module.exports = HuntService;

and the controller:

class HuntController extends \BaseController {

    public function saveItems() {
        Session::put('hunts', Input::get('hunts'));
        return Response::json(array('saved' => true), 200);
    }

    public function destroy($id) {
        Session::forget('hunts');
    }

     public function getHunts() {
        return Session::get('hunts') // dont exits
    }

}

And when im trying as test to get to this with regular request and no ajax its working.

The problem is here:

var hunts = this.hunts;

Here, this.hunts does not exist.

NOTE:

Use Inspect Element/Debug tool for inspecting the request & check whether it is sending any value for hunts attribute in post method or just blank. The laravel part looks ok.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM