Skip to content

Instantly share code, notes, and snippets.

@iWader
Last active December 29, 2015 09:28
Show Gist options
  • Save iWader/7650167 to your computer and use it in GitHub Desktop.
Save iWader/7650167 to your computer and use it in GitHub Desktop.
Sending ajax with dynamic key name
$(document).ready(function() {
function ajax_save(field, value)
{
$.ajax({
type: 'POST',
url: '{{ URL::to('/test') }}',
data: field + '=' + value
}).done(function(data) {
console.log('Response: ' + data);
}).fail(function(data) {
console.log('Failed: ' + data);
});
}
$('#input_1').blur(function() {
ajax_save('input_1', $('#input_1').val());
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment