我已经绑定了我能想到的所有东西,但出于某种原因如果我尝试通过ajax或者使用fancybox的iframe从gist加载原始文件,它将无法正常工作。它在浏览器中工作正常。有什么想法吗?
<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
}
});
});
});
完整演示:
答案 0 :(得分:0)
如果您尝试从浏览器执行此操作,则可能会被Same-Origin策略停止。 Read More Here
除非你使用类似JSONP的东西,否则基本上你不能发出跨站点的ajax请求。