如何从返回$ .getJSON值附加信息?
以下是$ .getJSON的返回数据
测试
一旦从带有变量testNumber的$ .getJSON调用返回,我需要向此内部元素添加其他信息。
<p> Test + testNumber + </p>
这是我的尝试,但没有以正确的方式工作....
$.getJSON("getTestInformation.php", function(function(data)
{
$.each(data, function()
{
$(".addTest").html(value).append(testNumber);
});
});
我得到的输出是:
<p> Test </p> 1
我需要的是这个吗?
<p> Test 1 </p>
答案 0 :(得分:0)
使用:
$.each(data, function(index, value) {
$('<p>').html(value + ' ' + testNumber).appendTo('.addTest');
});
答案 1 :(得分:0)
这样的事情:
$.getJSON("getTestInformation.php", function(function(data)
{
$.each(data, function()
{
var txt = $(".addTest").text();
$(".addTest").text(text + ' ' + testNumber);
});
});
或
$.getJSON("getTestInformation.php", function(function(data)
{
$.each(data, function()
{
$(".addTest").html(value + $("<span>").text(testNumber));
});
});