用JS或者AJAX 的方法远程读取信息
[{"aa":a1,"bb":"22","cc":"33","dd":"44","ee":0},{"aa":a2,"bb":"22","cc":"33","dd":"44...
[{"aa":a1,"bb":"22","cc":"33","dd":"44","ee":0},{"aa":a2,"bb":"22","cc":"33","dd":"44","ee":0},{"aa":a3,"bb":"22","cc":"33","dd":"44","ee":0},{"aa":a4,"bb":"22","cc":"33","dd":"44","ee":0},{"a5":a3,"bb":"22","cc":"33","dd":"44","ee":0}......]
......的意思是后面还有很多组这样的数
以上为远程页面的信息
如http://127.0.0.1/1.asp?yy=a
请问如何用 JS或者AJAX 截取或者调用此页面 然后进行裁剪
页面得到
a1,a2,a3,a4,a5
效果
[{"aa":a1,"bb":"223","cc":"334","dd":"423","ee":0},{"aa":a2,"bb":"2d2","cc":"3343","dd":"44e","ee":0},{"aa":a3,"bb":"2223","cc":"3xx","dd":"443","ee":0},{"aa":a4,"bb":"225","cc":"3a3","dd":"444","ee":0},{"aa":a5,"bb":"2f2","cc":"3g3","dd":"44w","ee":0}......]
刚才的代码错了 应该是这样 展开
......的意思是后面还有很多组这样的数
以上为远程页面的信息
如http://127.0.0.1/1.asp?yy=a
请问如何用 JS或者AJAX 截取或者调用此页面 然后进行裁剪
页面得到
a1,a2,a3,a4,a5
效果
[{"aa":a1,"bb":"223","cc":"334","dd":"423","ee":0},{"aa":a2,"bb":"2d2","cc":"3343","dd":"44e","ee":0},{"aa":a3,"bb":"2223","cc":"3xx","dd":"443","ee":0},{"aa":a4,"bb":"225","cc":"3a3","dd":"444","ee":0},{"aa":a5,"bb":"2f2","cc":"3g3","dd":"44w","ee":0}......]
刚才的代码错了 应该是这样 展开
2个回答
展开全部
先说明:
a1,a2,a3,a4,a5,在返回的字符串中应该加",否则js会报错.除非在你的环境里,a1,...a5是已经定义的变量.
以下是使用代码.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function handler() {
var result = '[{"aa":"a1","bb":"223","cc":"334","dd":"423","ee":0},{"aa":"a2","bb":"2d2","cc":"3343","dd":"44e","ee":0},{"aa":"a3","bb":"2223","cc":"3xx","dd":"443","ee":0},{"aa":"a4","bb":"225","cc":"3a3","dd":"444","ee":0},{"aa":"a5","bb":"2f2","cc":"3g3","dd":"44w","ee":0}]';
//这里演示的是服务器返回的数据,字符串形式.这方法在回调函数中使用.在实例使用时,result应该替换为服务器返回的数据.
var resultjson = eval(result);
var div = document.getElementById("info");
for (var i = 0; i < resultjson.length; i++) {
div.innerHTML += resultjson[i].aa;
if (i < resultjson.length - 1) {
div.innerHTML += ",";
}
}
}
window.onload = handler;
</script>
</head>
<body>
<div id="info">
</div>
</body>
</html>
a1,a2,a3,a4,a5,在返回的字符串中应该加",否则js会报错.除非在你的环境里,a1,...a5是已经定义的变量.
以下是使用代码.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function handler() {
var result = '[{"aa":"a1","bb":"223","cc":"334","dd":"423","ee":0},{"aa":"a2","bb":"2d2","cc":"3343","dd":"44e","ee":0},{"aa":"a3","bb":"2223","cc":"3xx","dd":"443","ee":0},{"aa":"a4","bb":"225","cc":"3a3","dd":"444","ee":0},{"aa":"a5","bb":"2f2","cc":"3g3","dd":"44w","ee":0}]';
//这里演示的是服务器返回的数据,字符串形式.这方法在回调函数中使用.在实例使用时,result应该替换为服务器返回的数据.
var resultjson = eval(result);
var div = document.getElementById("info");
for (var i = 0; i < resultjson.length; i++) {
div.innerHTML += resultjson[i].aa;
if (i < resultjson.length - 1) {
div.innerHTML += ",";
}
}
}
window.onload = handler;
</script>
</head>
<body>
<div id="info">
</div>
</body>
</html>
展开全部
你用ajax获取以后,就可以直接用了。
var json = [{"aa":a1,"bb":"223","cc":"334","dd":"423","ee":0},{"aa":a2,"bb":"2d2","cc":"3343","dd":"44e","ee":0},{"aa":a3,"bb":"2223","cc":"3xx","dd":"443","ee":0},{"aa":a4,"bb":"225","cc":"3a3","dd":"444","ee":0},{"aa":a5,"bb":"2f2","cc":"3g3","dd":"44w","ee":0}......];
json[0] = {"aa":a1,"bb":"223","cc":"334","dd":"423","ee":0};
json[0].aa = a1;
json[0].bb = "223";
...
...
以此类推。
var json = [{"aa":a1,"bb":"223","cc":"334","dd":"423","ee":0},{"aa":a2,"bb":"2d2","cc":"3343","dd":"44e","ee":0},{"aa":a3,"bb":"2223","cc":"3xx","dd":"443","ee":0},{"aa":a4,"bb":"225","cc":"3a3","dd":"444","ee":0},{"aa":a5,"bb":"2f2","cc":"3g3","dd":"44w","ee":0}......];
json[0] = {"aa":a1,"bb":"223","cc":"334","dd":"423","ee":0};
json[0].aa = a1;
json[0].bb = "223";
...
...
以此类推。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询