-
-
Save wp-lab/0cd4d2fc2a6694c6b00a834b5c018ce5 to your computer and use it in GitHub Desktop.
How to dynamically get eBay ItemID 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
<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