JQuery XSS JSONP


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. });

URL: http://www.digitalscientists.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.