Skip to content

Instantly share code, notes, and snippets.

@imranismail
Last active August 29, 2015 14:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save imranismail/11111515 to your computer and use it in GitHub Desktop.
Save imranismail/11111515 to your computer and use it in GitHub Desktop.
Laravel + Jquery Ajax .post
//Javascript
$(function()
{
var BASE_URL = window.location.protocol + '//' + window.location.host;
$("#buttonselector").click(function() {
var data = {
'inputelementname' : $('#inputelementselector').val(),
};
$.post( BASE_URL + "/apply/ajax", data, function(response) {
console.log('Ajax loading successful');
console.log(response);
})
.fail(function() {
console.log('Ajax loading failed');
})
});
});
// Laravel Routes (you can use controller but this is just for testing)
Route::post('/apply/ajax', function()
{
$data = Input::get('inputelementname');
return $data
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment