lundi 21 août 2017

laravel Ajax success function not working

I send a store request to my laravel application through AJAX. The controller function works properly, but either I cannot get a success message in my ajax function, or the function on success is not working.

Ajax code:

$.ajax({
    type: "POST",
    url: 'http://ift.tt/2v71tJe',
    data: {
        description: description,
        offset_top: offset_top,
        offset_left : offset_left
    },
    success: function(msg){
        console.log("done");
    }
});

Controller's store function:

public function store(Request $request)
{
    echo $request;
    if (Auth::check()) {
        $user = Auth::user();
        $dream = new Dream($request->all());
        if ($dream) {
            $user->dreams()->save($dream);
            $response = array(
              'dream' => $dream,
              'status' => 'success',
              'msg' => 'Setting created successfully',
            );
            return \Response::json($response);
        }
        return \Response::json(['msg' => 'No model']);
    } else {
      return \Response::json('msg' => 'no auth');
    }
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2wwFIWK
via IFTTT

Aucun commentaire:

Enregistrer un commentaire