gpt4 book ai didi

javascript - 为什么我无法在JQuery中获取变量值

转载 作者:行者123 更新时间:2023-11-28 15:46:14 25 4
gpt4 key购买 nike

我开发了使用 JQuery 获取 JSON 数据的工具,但问题是有些变量没有放置它们的值,并且我只得到了像文本一样的变量名称。这是代码

$(document).ready(function(){
$('.HTML').each(function(){
var call = $.getJSON('http://test-khamsat-support-gig.blogspot.com/feeds/posts/default/-/Break?max-results=10&orderby=published&alt=json-in-script&callback=?',function(data){
var cont = data.version;
});

var th = $(this);
var b = th.html(),
a = b.match(/[^[\]]+(?=])/g);
if(a){
if(a[2] == 'one'){
th.append("<h1>'+cont+'</h1>")
}
}
});
});

该代码将仅在我的博客中运行,因为它内容是我的 blog饲料

最佳答案

尝试

$(document).ready(function () {
$('.HTML').each(function () {
//store the reference to the element to use inside the callback
var th = $(this);
$.getJSON('http://test-khamsat-support-gig.blogspot.com/feeds/posts/default/-/Break?max-results=10&orderby=published&alt=json-in-script&callback=?', function (data) {
var cont = data.version;

//move this inside the ajax callback to support async nature
var b = th.html(),
a = b.match(/[^[\]]+(?=])/g);
if (a) {
if (a[2] == 'one') {
//use proper string concatenation here
th.append('<h1>' + cont + '</h1>')
}
}
});
});
});

关于javascript - 为什么我无法在JQuery中获取变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22173027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com