Skip to content

Instantly share code, notes, and snippets.

@imbcmdth
Created May 20, 2013 15:21
Show Gist options
  • Save imbcmdth/5612905 to your computer and use it in GitHub Desktop.
Save imbcmdth/5612905 to your computer and use it in GitHub Desktop.
AJAXRequest: function(url, action){
/* ----------------------
Small AJAX Library
------------------------- */
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
// check if the request is ready and the status is ok
if (xhr.readyState === 4 && xhr.status === 200){
action(xhr);
}
}
xhr.open("GET", url, true); // Setup before request
xhr.send(null); // Finally request the file
},
sendToAFriend: function(){
/* ------------------------------------
Opens a modal with "Send to a Friend" form
--------------------------------------- */
document.id('friend-mailer-link').addEvent('click', function(){
jQuery('#myModal').reveal({
animation: 'fade'
});
this.AJAXRequest('/friend-mailer/{{article.id}}/', function(xhr){
var grabModal = document.getElementById('myModal-inner');
grabModal.innerHTML = xhr.responseText;
});
return false;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment