Wednesday, June 24, 2015

laravel 5 ajax POST

Standard

hi guys here is basic AJAX POST on laravel 5 i hope this will help for your advance project

 thank you


Route::group(['prefix' => 'ajax'], function() {

    Route::get('/ajax', 'AjaxController@ajax');
    Route::post('/ajaxpost', 'AjaxController@ajaxpost');

});
 
<pre class="java" name="code">
             <input id="name" name="name" type="text" value="hello channa" />
             <input id="__token" name="__token" type="hidden" value="uAVNLARzB2zKp2hJElHXNRGSGLJ0gwqibXyqRXci" />

             <input class="submit" id="submit" type="submit" />

           
<div id="loadingmessage" style="display: none;">
<img src="loading.gif" />                                                                            
  </div>
<div id="my_div">
</div>
<script>

        $('#submit').click(function(){
        $('#loadingmessage').show();  // show the loading message.
        $.ajax({
            type: "POST",
            url: "http://localhost/bitbuckt/public/staff/ajaxpost",
            dataType: "html",
            data: { "_token" : "uAVNLARzB2zKp2hJElHXNRGSGLJ0gwqibXyqRXci" },
            success: function( response) {
              $('#my_div').html(response);
              $('#loadingmessage').hide(); // hide the loading message
     
            }
          });

        });

        </script>

</pre>
create view form under resources -&gt; view -&gt; ajax -&gt;ajax.blade.php
i passed _token key with data

create response action on AjaxController
 

    public  function ajaxpost()
    {

        print_r('data response ');
    } public  function ajax()
    {
        return view('staff.ajax');
    }

 

1 comment:

  1. First of all, thank you for all the useful information. I would like to thank you for emphasizing the importance of playing an important role in the accommodation industry. I appreciate your hard work. Keep posting new updates with us.

    DedicatedHosting4u.com

    ReplyDelete