jQuery中的.get()不';行不通
我对jQuery方法.get()有问题。在以前的代码中,我有这样一个:jQuery中的.get()不';行不通,jquery,Jquery,我对jQuery方法.get()有问题。在以前的代码中,我有这样一个: $('.quote_button').click(function(){ var enlace = $('a', this).attr('href'); $.get(enlace, function(replyPost){ var QuoteContent = $(replyPost).find('.editor').html(); $('textarea[name=m
$('.quote_button').click(function(){
var enlace = $('a', this).attr('href');
$.get(enlace, function(replyPost){
var QuoteContent = $(replyPost).find('.editor').html();
$('textarea[name=message]').val($('textarea[name=message]').val() + QuoteContent);
});
});
这很好用。但在新的代码中,我不明白我想要它。这:
$('#linkFile').click(function(){
var linkFL = "http://pastebin.com/embed_js.php?i=sy9gt3FR";
$.get(linkFL, function(data){
var onLine = $(data).find('.embedFooter a:nth-child(3)').text();
alert(onLine); //onLine is undefined
});
});
我不明白,因为我测试了如何将linkFL.html中的“.embeddefooter”元素添加到local.html中,并且工作得非常完美(onLine=“See original”)。但是调用$.get()不会(onLine=未定义)
有什么想法吗(
编辑:使用嵌入代码(工作)和调用.get()(不工作)编写代码
如评论中所述,您不能进行跨域AJAX查询 如果要解决此问题,可以使用:
.get()
在jQuery中确实有效!!!!看起来以前您可能是从同一来源加载资源,现在您是从不同的域加载资源,导致了冲突是的,第一个代码是从同一页面加载的,第二个代码是外部页面。因此,我不可能要它吗?抱歉,但在函数(数据)中要获取“.embeddefooter a:nth child(3)”,例如,我应该编写什么?@Madh,很抱歉,JSONP仅适用于JSON对象(您的链接返回文本/html mime类型)。解决问题的最佳方法是使用。
$.ajax({
url: "http://pastebin.com/embed_js.php?i=sy9gt3FR",
dataType: "jsonp",
success: function (data) {
// ...
}
});