Jquery ajax html replace
Jquery ajax html replace
我的问题很简单我收到字符串和一个数字,但只显示数字如何同时显示两者?
$.ajax({
type: "POST",
url: "data.php",
data: "act="+nr,
success: function (result) {
var arr = JSON.parse(result);
if ($.isArray(arr) == true) {
$.each(arr, function (i, n) {
$('#s_main #s_info').html("<p>+" + n + "</p>")
});
}
}
})
}); //ends here
我的PHP:
$act = $_POST['act'];
$output =array();
$act2 = "TXT!!!";
array_push($output,$act);
echo json_encode($output);
顺便说一句,当我使用 append 而不是 html 时,结果是正确的,但它会堆叠而不会删除以前的数据
你得到的回报是一个JSON对象。
if ($.isArray(arr) == true)
此行不应返回 true,因为对象不是数组。 如果JSON.parse()
不起作用,它将返回一个等于 false 的值。 因此,您可以简单地测试返回的对象以查看它是否成功。
var jsonObj = JSON.parse(result);
if (jsonObj) {
$.each(jsonObj, function (index, value) {
$('#s_main #s_info').html("<p>+" + value + "</p>")
});
}
相关文章:
- JavaScript .replace HTML 标记不会替换
- 将 HTML 标记替换为 Grunt-Replace
- 将 html 代码放在 StringObject.replace() 中
- How to do "HTML FORM action=location.replace('nextp
- 使用 Javascript 的 replace() 方法用 html 包装单词
- Jquery ajax html replace
- Using html <template>: innerHTML.replace
- 将 HTML 部分替换为 replace()
- Javascript:replace() 所有,但只在 html 标记之外
- 使用具有全局值的Javascript replace()时,ng绑定html中断
- Replace HTML with JavaScript
- Javascript replace()使用html实体
- gulp-rev-replace替换子文件夹中的HTML文件
- javascript regex replace html
- 使用.replace将文本替换为HTML
- 我想使用Javascript replace()来添加html标记(但它将它们作为字符串返回)
- 如何移除竖条"|"从HTML中使用replace()
- Javascript - Replace html using innerHTML
- getElementById replace HTML
- Replace html of a td