Working with JSONPCallbacks for Enrichments

Bronze Contributor
Bronze Contributor
//callback function
	function jsonpcallback(data) {
		//do stuff with JSON
		if(data.job_detail_id == utag_data.job_detail_id) {
		        console.log(data.detail_id == utag_data.detail_id);
			utag_data.TEA_location = data.TEA_location;
	    	        utag_data.TEA_branche = data.TEA_branche;
	    	        console.log(utag_data);
		}
	}

	//create HTML script tag
	var scripthdl = document.createElement('script');
	scripthdl.src='//domain/stelle.js?callback=jsonpcallback';

	//inject script tag into head
	document.getElementsByTagName('head')[0].appendChild(scripthdl);

With this little JavaScript, i'm trying to access a JSON file, which by now is looking like this:

jsonpcallback({"detail_id" : "1234567",
    "TEA_location" : "Kalkutta",
    "TEA_branche" : "Media"
});

On my local machine this works perfect, but if i let Tealium run this, i get an error: 

Uncaught ReferenceError: jsonpcallback is not defined at stelle.js?callback=jsonpcallback:1

What am I doing wrong?


Thanks in advance!

2 REPLIES 2

Working with JSONPCallbacks for Enrichments

Tealium Expert
Tealium Expert

If you're running that within a function, then it'll be creating the jsonpcallback function locally, which means it won't be accessible to the script that's returned by the JSONP request.

Instead, try replacing that first (non-comment) line with:

window.jsonpcallback = function(data) {

Working with JSONPCallbacks for Enrichments

Bronze Contributor
Bronze Contributor
Thank you! It worked.
Public