how make page not refresh after submit 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() }} alternative way tried:
<form method="post" action="../booking/unit/" id="readform" > <input value="{{$booking->id}}" hidden name="bookingid" /> <input value="{{$booking->unit}}" hidden name="unitid" /> <button class="btn btn-warning" type="submit" id="readbtn" >{{ $booking->status }}</button> </form> //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 still refreshing. why?
updates [22nd july 2015] have multiple table rows forms , forms having same id. caused refreshing happened except first row of form. have changed form id class , solved! thank everyone! guys awesome , answers valuable. careful next time. :d
$("#readform").submit(function(e){ e.preventdefault(); }); have tried e.preventdefault in ajax function. stops refreshing page
Comments
Post a Comment