Skip to content

Instantly share code, notes, and snippets.

@websupporter
Last active April 11, 2016 12:10
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 websupporter/614ff6c913878e51a150b339ae561a0f to your computer and use it in GitHub Desktop.
Save websupporter/614ff6c913878e51a150b339ae561a0f to your computer and use it in GitHub Desktop.
Ajax Request in Javascript
jQuery.ajax({
url: dnStrings.ajax_url,
data: {
'since':wpNotifyCurrentDate
},
method: 'GET',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', dnStrings.nonce );
},
success: function( response ){
var msg_send = false;
for( var i = 0; i < response.length; i++ ){
if( -1 == jQuery.inArray( response[i].type + '-' +response[i].id, wpNotifiedIDs ) && !msg_send){
msg_send = true;
wpNotifiedIDs.push( response[i].type + '-' + response[i].id );
window[dnStrings.callback]( response[i].title, response[i].content, response[i].avatar, response[i].link );
}
}
if( response.length > 0 )
sessionStorage.setItem( 'wpNotifiedIDs', wpNotifiedIDs );
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment