mercredi 15 février 2017

404 Not Found Error comes up while sending post AJAX request to Laravel Controller

I am trying to send dta from view to Laravel Controller via ajax post call. and it giving me error 404 not found i have checked things many but i cant find mistake.

class AttemptController extends Controller {
     public function postSavegame(Request $request) {
        $data = $request->all();
        print_r($data);
        //insert data to db
        $id = $this->model->insertRow($data, $request->input($data));

        // Insert logs into database
        if ($id != '') {
             \SiteHelpers::auditTrail($request, 'New Data with ID ' . $id . ' Has been Inserted !');
            echo('Done');
        } 
    }
}

here is the AJax from view:

$.ajax({
            method: 'POST',
            url: "",
            data: {
                quiz_id: localStorage.quiz_id,
                user_id: "",
                total_score: localStorage.achivePoints, // a JSON object to send back
                success: function (response) { // What to do if we succeed
                    console.log(response);
                },
                error: function (jqXHR, textStatus, errorThrown) { // What to do if we fail
                    console.log(JSON.stringify(jqXHR));
                    console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
                }
            },
        });

and this is my route entry

Route::post("gameSave", "AttemptController@gameSave");



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

Aucun commentaire:

Enregistrer un commentaire