Skip to content

Instantly share code, notes, and snippets.

@stevebooks
Created May 17, 2013 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevebooks/5600118 to your computer and use it in GitHub Desktop.
Save stevebooks/5600118 to your computer and use it in GitHub Desktop.
$.ajax
url: "/sheets/1" #+ @extraUrlParams
type: "PUT"
contentType: "application/json"
data: JSON.stringify([change])
dataType: "json"
success: (data, textStatus, jqXHR) =>
$('#sheet-errors').hide('slow') #if there are errors
#handleUpdateResponse(data)
this.receivedAjax(data)
error: (jqXHR, textStatus, errorThrown) =>
#console.log jqXHR
#console.log textStatus
#console.log errorThrown
errorText = "Check your internet connection and try again."
if errorThrown == "Unauthorized"
responseText = jqXHR['responseText']
if responseText && responseText == 'access_denied'
errorText = "You don't have permissions to modify these records"
else
#They need to log back in
#just refresh the page and it will redirect
document.location.reload(true)
return
else
if errorThrown == 'Internal Server Error'
errorText = "We have been notified of the issue, check back soon."
else
errorText = "Check your internet connection and try again."
this.showAjaxError(errorText)
$('form').submit(function() {
var valuesToSubmit = $(this).serialize();
$.ajax({
url: $(this).attr('action'), //sumbits it to the given url of the form
data: valuesToSubmit,
dataType: "JSON" // you want a difference between normal and ajax-calls, and json is standard
}).success(function(json){
//act on result.
});
return false; // prevents normal behaviour
});
@stevebooks
Copy link
Author

$('form.add_transaction').submit ->
return false if hasErrors($(this))

Add spinners

#send ajax to server
formData = $(this).serialize()
$.ajax
url:
data: formData

return false;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment