Skip to content

Instantly share code, notes, and snippets.

@mikealmond
Created February 7, 2012 02:43
Show Gist options
  • Select an option

  • Save mikealmond/1756791 to your computer and use it in GitHub Desktop.

Select an option

Save mikealmond/1756791 to your computer and use it in GitHub Desktop.
Conditionally send data to a jQuery Ajax request
var data = {
'id': 1,
'body': $('#body').val()
};
if (hasTitle == true) {
data['title'] = $('#title').val();
}
$.post('/ajax/update-something', data, function (response) {
$('#template').html(response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment