mardi 23 février 2016

No saved correctly JSON data sent by AJAX to laravel controller

Hi I'm building an application laravel 5.2, and I have a problem, the problem is that I only save the data from JSON, not the header information you see on the bottom. I wonder what I'm doing wrong. Thanks

The Ajax in the view

$.ajax({
          url: 'http://{!! $_SERVER['SERVER_NAME'] !!}/settings/languages_available/{!!$lang->id!!}/update_target',
          type: "put",
          data: {"target":""+JSON.stringify(data_rate)+""},
          success: function(data){
            console.log(data);
          }
        });  

The function in the controller

 public function updateTargetLanguages(Request $request, $id)
    {
        $LA = LanguageAvailable::find($id);    
        $LA->target_languages = response()->json($request);
        $LA->save(); 
    }

In the database is stored in this way:

HTTP/1.0 200 OK
 Cache-Control: no-cache
 Content-Type:  application/json

 {"target":"[{\"title\":\"Brazilian Portuguese\",\"rate\":\"0.04\"},{\"title\":\"Belarusian\",\"rate\":\"0.06\"},{\"title\":\"Canadian French\",\"rate\":\"0.06\"}]"}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire