jchris (owner)

Revisions

gist: 23684 Download_button fork
public
Description:
for the cross domains
Public Clone URL: git://gist.github.com/23684.git
Embed All Files: show embed
jquery.xdompost.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// cargo culted bits from here: http://dev.jquery.com/ticket/3342
 
// Usage:
// $.xdom.post('http://example.com/post-to-here',{"foo":"bar"});
// Sends a POST to http://example.com/post-to-here with content foo=bar
 
(function($) {
  $.xdom = $.xdom || {};
  
  function now(){
   return +new Date;
  }
  
  var ifc = now();
  
  $.fn.extend($.xdom,{
    post : function(url, data) {
      var ifr = "ifr" + ifc++;
     var iid = 'xdom_' + ifr;
     $('body').append('<iframe id="'+iid+'" name="'+iid+'"/>');
     var iframe = $('#'+iid)[0];
     var op8 = $.browser.opera && window.opera.version() < 9;
     if ($.browser.msie || op8) iframe.src = 'javascript:false;document.write("");';
     $(iframe).css({ position: 'absolute', top: '-1000px', left: '-1000px' });
    
     var fid = 'form_' + ifr;
     $('body').append('<form id="'+fid+'" name="'+fid
     + '" method="POST" action="'+url+'" target="'+iid+'"/>');
     var form = $('#'+fid)[0];
     $(form).css({position: 'absolute', top: '-1000px', left: '-1000px' });
    
     $.each(data, function(key, value) {
     var inid = 'input_'+ifr+'_'+key;
     $(form).append('<input id="' + inid + '" name="'
     + key +'" type="text"/>');
   $('#'+inid).val(value);
     });
    
     form.submit();
    }
  });
})(jQuery);