The My Opera forums have been replaced with forums.opera.com. Please head over there to discuss Opera's products and features

See the new Forums

Adding a callback function when JSONP data is loaded

Forums » General Opera topics » Opera extensions

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

5. October 2011, 19:58:41

cyberstream

Posts: 113

Adding a callback function when JSONP data is loaded

A few months ago, I posted a question regarding how to intercept AJAX requests so my extension could work on websites like Twitter. My current implementation is OK, but I was looking at the source code of Tweetspeak to find out how rbardini added to "Speak" button to each tweet. I saw he used jQuery to run a callback function when a new batch of tweets loaded:

return $.ajax({
	url: baseUri+methodName,
	dataType: "jsonp",
	jsonp: "oncomplete",
	data: data
}).success(function(data) {
	if (typeof callback === 'function') {
		callback(data);
	}
});


So my question is, how, in plain JS, can I make a callback function run each time JSONP data is received asynchronously?

9. October 2011, 04:10:16

spadija

Posts: 1643

How about making a magic function that overrides "oncomplete" (and calls the original function)? If I understand JSONP correctly, the request will return a script in the format "oncomplete({ json data goes here })", so overriding "oncomplete" should work.

Forums » General Opera topics » Opera extensions