Created
May 17, 2013 16:06
-
-
Save stevebooks/5600118 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$('form.add_transaction').submit ->
return false if hasErrors($(this))
Add spinners
#send ajax to server
formData = $(this).serialize()
$.ajax
url:
data: formData
return false;