Please guys how do i a nice laravel ajax post and get the data in laravel backend.
my code
my route.php
Route::post('dashboard','AjaxPostsController@tell_us_box_post');
My controller function
public function tell_us_box_post()
{
$post = input::get('data')
return View::make('home.dashboard.MyAccount');
}
my jquery code
url = 'http://localhost/laravel4/app/views/home/dashboard/mydashboard.blade.php';
data = tellusboxvalue;
datatype='text';
jQuery.post( url, data, function( data, textStatus, jqXHR )
{
return textStatus;
},datatype );
Your url is the path to the controller file, it should be the route adress
you can use the Request::ajax()
to make sure that you only response to the ajax requests, and as pmall said, you ajax request must be your route url ( check https://github.com/aaronlord/laroute if you want to use your routes within your javascript files)
if (Request::ajax()) {
return View::make('class.ajax_new', $data);
} else {
return View::make('class.new', $data);
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community