Automatic Ajax request

Posted 11 months ago by david001

Is there any tricks to send ajax data to controller without click event in view. I mean when user visit to the home page(url:'/home') i want to send some data to another url(ie: '/getValue')without clicking submit button.

My js in home.blade.php is

<script type="text/javascript">
        var username = "john";

          success: function(data) {


my controller is

public function receiveData(Request $request)
    return $request->username;
       // i need to get here "john" 


Route::get('getValue','[email protected]');

How can i get username 'John'to controller

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.