Created
February 22, 2012 16:50
-
-
Save mindscratch/1885993 to your computer and use it in GitHub Desktop.
JavaScriptMVC Stuff
This file contains hidden or 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
| // do this once dom is ready | |
| $(document).ajaxSend(function(e, xhr, options) { | |
| var token = $("meta[name='csrf-token']").attr("content"); | |
| xhr.setRequestHeader("X-CSRF-Token", token); | |
| }); |
This file contains hidden or 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
| // convenient way of extracting 'error' from JSON | |
| // example JSON response: | |
| // {error: 'something bad happened!'} | |
| $.fn.error_from_xhr = function(jqXhr) { | |
| if (jqXhr && jqXhr.responseText) { | |
| var resp = $.parseJSON(jqXhr.responseText); | |
| if (resp && resp.error) { | |
| return resp.error; | |
| } | |
| } | |
| return "unknown"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment