0

I have tied everything I can think of but for some reason If I try to load the raw file from gist via ajax or in an iframe with fancybox or something it won't work. It works fine in the browser though. Any ideas?

<a class="raw-file" href="https://gist.github.com/raw/2408789/2da6f8b2377cdb86ac0b7a005eec1c1b90459569/Jquery-click-prevent-redirect.txt">Jquery-click-prevent-redirect.txt</a>
<div>results here...</div>

$(document).ready(function() {
    $("a").click(function(event){
            jQuery.ajax({
               url: $(this).attr('href'),
               dataType: "json",
               beforeSend: function(){
                   $(this).closest('div').html('getting file...');
               },
               success: function(data) {
                    $(this).closest('div').html(data);
               },
               complete: function(){
                   //stuff here
               }
          });
    });
});

full demo here:

http://jsfiddle.net/aseabridge/5jfBm/2/

Adam Seabridge
  • 1,909
  • 1
  • 20
  • 27

1 Answers1

0

If you are trying to do this from a browser, you are probably getting stopped by the Same-Origin policy. Read More Here

Basically you can't make cross-site ajax requests unless you use something like JSONP.

ericb
  • 3,400
  • 1
  • 21
  • 21
  • thanks I had a go at this but even thought the response is coming back in firebug ok it doesn't alert the reponse or append it to a div. Demo here: http://jsfiddle.net/aseabridge/WKFSD/ – Adam Seabridge Apr 18 '12 at 02:08