4 years ago

Ajax Posting data into the database.

Posted 4 years ago by nanadjei2

please this is my blade.

Drink A Coffee today

Coffee Orders

<h4>Add a Coffee Order</h4>
{!! Form::open(['url' => 'index', 'method' => 'POST']) !!}
    <div class="form-group" role="form">
    <label for="name">Name:</label>
    <input id="name" type="text" name="name" class="form-control">

    <label for="drink">Drink:</label>
    <input id="drink" type="text" name="drink" class="form-control">
    <button id="add-order" class="btn btn-default" type="submit">Add!                </button>
{!! Form::close() !!}

and my script is as follows.

$(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 data = $(this).closest('form').serialize();

    var request = $.ajax({

        url: "index",
        type: "POST",
        data: data,

        request.done(function( msg ) {
            var response = JSON.parse(msg);
        }); jqXHR, textStatus ) {
            console.log( "Request failed: " + textStatus );


But anytime i try to submit the form, nothing happends.

Please sign in or create an account to participate in this conversation.