如何在html页面中从ajax返回json数据
how to return json data from ajax in html page
如何在html页面中返回json数据。我在js文件中有这段代码
$.ajax({
url : 'auth.json',
type: "GET",
dataType : "jsonp",
success: function(result) {
$.each(result, function(i, v) {
// For each record in the returned array
$('#div_id').append(v.room_id);
});
index.html是
<!DOCTYPE html>
<html>
<title>AjaxCall</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="ajax.js"></script>
<body>
<div id="room_id">
</div>
</body>
</html>
我有json文件。但我不知道该怎么做。请帮帮我。谢谢!
您的代码看起来不完整。此外,您应该使用div ID"room_ID",而不是错误的"div_ID"。
$.ajax({
url : 'path'auth.json',
type: "GET",
dataType : "json",
success: function(result) {
$.each(result, function(i, v) {
$('#room_id').append(v.room_id);
});
}
});
相关文章:
- JS验证ajax返回的html中的表单数据
- Morris.js无法显示ajax返回的数据
- 统计ajax返回数据中的html元素
- 在Smarty中定义AJAX返回的格式
- 如何从ajax返回两个html内容
- 如何使用 AJAX 返回 JS 值
- 从Ajax返回时执行Javascript
- JQuery无法处理ajax返回的内容
- 保存通过Ajax返回的信息后出现$_POST错误
- 我需要从ajax返回值
- 如何在html页面中从ajax返回json数据
- ajax 返回带有循环的图像长度,检查最后一个循环
- Jquery ajax返回错误
- 对从Ajax返回的数据使用Jquery方法,不打印数据
- ajax返回空字符串,而不是json[python-cgi]
- 然后在ajax返回之前运行
- 使用 AJAX 返回 json 数组
- 在 php 上使用 ajax 返回值
- jQuery验证后,$.ajax返回HTML源代码
- 根据 Ajax 返回的数据提交表单