Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Jquery加载Gist原始文件_Jquery_Ajax_Git_Gist - Fatal编程技术网

从Jquery加载Gist原始文件

从Jquery加载Gist原始文件,jquery,ajax,git,gist,Jquery,Ajax,Git,Gist,我已经把我能想到的一切都联系在一起了,但是由于某种原因,如果我试图通过ajax从gist加载原始文件,或者在带有fancybox的iframe中加载原始文件,或者其他一些东西,它将无法工作。但它在浏览器中运行良好。有什么想法吗 <a class="raw-file" href="https://gist.github.com/raw/2408789/2da6f8b2377cdb86ac0b7a005eec1c1b90459569/Jquery-click-prevent-redirect.

我已经把我能想到的一切都联系在一起了,但是由于某种原因,如果我试图通过ajax从gist加载原始文件,或者在带有fancybox的iframe中加载原始文件,或者其他一些东西,它将无法工作。但它在浏览器中运行良好。有什么想法吗

<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
               }
          });
    });
});

结果在这里。。。
$(文档).ready(函数(){
$(“a”)。单击(函数(事件){
jQuery.ajax({
url:$(this.attr('href'),
数据类型:“json”,
beforeSend:function(){
$(this.closest('div').html('get file…');
},
成功:功能(数据){
$(this).closest('div').html(数据);
},
完成:函数(){
//这里的东西
}
});
});
});
这里有完整的演示:


如果您试图从浏览器执行此操作,可能会被同一来源策略阻止


基本上,除非您使用类似JSONP的东西,否则您无法发出跨站点ajax请求。

谢谢,我尝试过了,但即使响应是在firebug中返回的,它也不会提醒响应或将其附加到div中。演示如下: