Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

Common Ajax Function in Laravel 5

by
Category:laravel
ajax laravel
Common Ajax Function in Laravel 5

Ajax makes your application more flexible, you don't need to reload or refresh the whole body for small changes, you can made changes in any part without loading page.

How to Call ajax in Laravel 5

File Upload in Laravel 5 using Ajax With Form Data

Html head declare in meta tag.

<meta name="csrf-token" content="{{ csrf_token() }}" />

Common Ajax function declare.

var xhr;
function request_call(url,mydata)
{
    if(xhr && xhr.readyState != 4){
        xhr.abort();
    }

    xhr = $.ajax({
        url: url,
        type :'post',
        dataType: 'json',
        data : mydata,
    });
}

Call to route using Ajax

$('#gerResult').delegate('.ViewDiamondDetail','click', function(event){
   var loatno = this.id;
   var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
    request_call("{{url('view-diamond-detail')}}",'_token='+CSRF_TOKEN+'&loatno='+loatno);
    xhr.success(function( mydata ) {
         $('#myModal').html(mydata.success);
         $('#myModal').modal('show'); 
    });
});

Routes to Controller call

Route::post('view-diamond-detail', [
    'as' => 'view-diamond-detail',
    'uses' => 'SearchDiamondController@ViewDiamondDetail'
]);

Controller function

public function ViewDiamondDetail(Request $request)
{

}

How to Middleware work with route to super admin panel, admin panel, and user panel.


0 Comments


Html code work in comment box


Related Post