Posted By

twoism on 04/30/08


Tagged

plugin jquery xss JSONP


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

BlueCockatoo
ntulip
wirenaught


JQuery XSS JSONP


 / Published in: JavaScript
 

URL: http://www.digitalscientists.com

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

  1. $.fn.jsonp = function(params) {
  2. var qs = '?callback='+params.callback;
  3. if (params.data) {
  4. for(var v in params.data) {
  5. qs += ('&'+v+'='+params.data[v]);
  6. }
  7. }
  8. var url = params.url+qs;
  9. var time = new Date().getTime().toString();
  10. url += ('&'+ time);
  11. var tag = $('<script type="text/javascript" src="'+url+'" id="'+time+'">');
  12. var scriptTag = $(this).append(tag);
  13. return $(tag);
  14. }
  15. function boo(res) {
  16. alert('loaded!')
  17. }
  18. $(document).ready(function(){
  19. params = {
  20. callback:'boo',
  21. data:{
  22. q:'test'
  23. },
  24. url:'http://somesite.com/jsonp'
  25. };
  26. $('body').jsonp(params);
  27. });

Report this snippet  

You need to login to post a comment.