Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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