Return to Snippet

Revision: 6141
at April 30, 2008 11:51 by twoism


Initial Code
$.fn.jsonp = function(params) { 
	var qs 	= '?callback='+params.callback;
	if (params.data) {          				
		for(var v in params.data) {
			qs += ('&'+v+'='+params.data[v]);
		}
	}
	var url 		= params.url+qs;  
	var time 		= new Date().getTime().toString();
	url 	   	   += ('&'+ time);             
	var tag 		= $('<script type="text/javascript" src="'+url+'" id="'+time+'">');
	var scriptTag = $(this).append(tag);
	return $(tag);
}
function boo(res) {
	alert('loaded!')
}               
$(document).ready(function(){
	params = {
		callback:'boo',
		data:{
			q:'test'
		},
		url:'http://somesite.com/jsonp'
	};
	$('body').jsonp(params);
});

Initial URL
http://www.digitalscientists.com

Initial Description
After having trouble with xss and .getJSON() I wrote this. Solved my problems so here you go.

Initial Title
JQuery XSS JSONP

Initial Tags
plugin, jquery

Initial Language
JavaScript