Last active
April 11, 2016 12:10
-
-
Save websupporter/614ff6c913878e51a150b339ae561a0f to your computer and use it in GitHub Desktop.
Ajax Request in Javascript
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
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