dimanche 27 septembre 2015

Laravel Ajax posting data into the database

This is my blade.php =>

Drink A Coffee todayCoffee OrdersAdd a Coffee Order {!! Form::open(['url' => 'index', 'method' => 'POST']) !!}Name:

Drink:

Add!

{!! Form::close() !!}This is my controller => public function makeOrder() { if (Request::ajax()) { $post = Request::all(); $order = new Order; $order->name = $post['name']; $order->drink = $post['drink']; $order->save(); return redirect()->back(); $response = array( 'status' => 'success', 'msg' => 'Option created successfully', ); return Response::json( $response ); }this is my scripts=> $(document).ready(function() { $('#add-order').click(function(e) { e. preventDefault(); //setting variables based on the input fields var inputName = $('input[name="name"]').val(); var inputDrink = $('input[name="drink"]').val(); var token = $('input[name="_token"]').val(); var data = {name:inputName, drink:inputDrink, token:token}; var request = $.ajax({ url: "index", type: "POST", data: data, dataType:"html" }); request.done(function( msg ) { var response = JSON.parse(msg); console.log(response.msg); }); request.fail(function( jqXHR, textStatus ) { console.log( "Request failed: " + testStatus ); }); });}); But anytime i submit my form and i the 'inspect element', i see this error "Uncaught ReferenceError: testStatus is not defined"

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

Aucun commentaire:

Enregistrer un commentaire