Skip to content

Instantly share code, notes, and snippets.

@wp-lab
Last active June 2, 2016 10:18
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 wp-lab/0cd4d2fc2a6694c6b00a834b5c018ce5 to your computer and use it in GitHub Desktop.
Save wp-lab/0cd4d2fc2a6694c6b00a834b5c018ce5 to your computer and use it in GitHub Desktop.
How to dynamically get eBay ItemID in JavaScript
<script type="text/javascript">
function wpl_process_ebay_item_id_jsonp(ebayID) {
// console.log('jsonp: ', ebayID);
window.ebayItemID = ebayID;
document.getElementsByClassName('wpl_ebay_item_id_wrapper')[0].innerHTML = ebayID;
}
if ( typeof window.ebayItemID == 'undefined' ) {
var script = document.createElement('script');
script.src = '[[admin_ajax_url]]' + '?action=wpl_ebay_item_query&callback=wpl_process_ebay_item_id_jsonp&id=' + '[[wpl_listing_id]]';
document.getElementsByTagName('head')[0].appendChild(script);
// or document.head.appendChild(script) in modern browsers
} else {
wpl_process_ebay_item_id_jsonp( window.ebayItemID );
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment