Lynx
Lynx

Reputation: 1482

Sending asynchronous data to controller

How can I post the data from Ajax to the controller to get back inputted data? I have it already working with static information but would like a post back information from a table.

Script

    function postdata(data) {
    $.post("{{ URL::to('book/postdate') }}", { input:data }, function(returned){
        $('.book').html(returned);
    });
}

HTML

{{ Form::text('date','', array('class' => 'datepicker', 'onChange' => 'postdata(this.value);')) }}

<div class="book"></div>

Routes

Route::post('book/postdate', 'BookController@postDate');

Controller

public function postDate() {

    echo 'hello';
}       

Echoing Hello works fine but I want to send data to the controller with a response.

Upvotes: 0

Views: 219

Answers (1)

giannis christofakis
giannis christofakis

Reputation: 8321

public function postDate() {
     $date = Input::get('input');
     //Do whatever process you want.
     return "You post date: ".$date;
} 

You can see the result in your console if you want

console.log(returned);

Upvotes: 1

Related Questions