Submit Form using AJAX in Laravel 4

How to make the page not refresh after I submit with the help of using AJAX in LARAVEL 4?

//xx.blade.php

{{ Form::open(['url' => '/booking/unit', 'method' => 'POST', 'id' => 'readForm']) }}
{{ Form::hidden('bookingid', $booking->id) }} 
{{ Form::hidden('unitid', $booking->unit) }} 
<button class="btn btn-warning" data-toggle="collapse" data-target="#{{$booking->id}}" type="submit">{{ $booking->status }}</button>
{{ Form::close() }}

//js

$("document").ready(function(){
$("#readForm").submit(function(){
    data = $(this).serialize();
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "../booking/unit", 
        data: data,
        success: function(data) {
            alert("Form submitted successfully.nReturned json: " + data["json"]);
        }
    });
    return false;
});

});

my page is still refreshing. why?


Source: ajax

Leave a Reply