ITPub博客

首页 > 应用开发 > > js获取json字符串结果

js获取json字符串结果

作者:farshow 时间:2019-09-09 10:16:32 0 删除 编辑

PHP中利用sqlsrv_fetch_array将结果转换为以下格式:

{"PatientID":1,"PatientName":"陈test","IdentityCardNo":"5245655455555545"}{"PatientID":22,"PatientName":"testchild","IdentityCardNo":"205003"}{"PatientID":168,"PatientName":"刘欣","IdentityCardNo":"5201031974102837"}{"PatientID":177,"PatientName":"刘宇","IdentityCardNo":"5201131903120417"}{"PatientID":178,"PatientName":"刘宇","IdentityCardNo":"5201131983120417"}

在HTML页面怎么用js循环遍历取出对应的值,以下是我的js代码:

function loadUse(){

var xhr = createXhr();

xhr.open("get","project.php",true);

xhr.onreadystatechange = function(){

if(xhr.readyState == 4 && xhr.status == 200){

//对响应数据的处理

//1.接收响应数据并转换为JS数组

var resText = xhr.responseText;

//var users = JSON.parse(resText);

var user = JSON.stringify(resText);

var users = JSON.parse(user);

//2.循环遍历数组,拼

var html ="";

for(var i = 0;i

//var user = resText;

var user = users[i];

console.log(user);

html += "";

html += " "+user.PatientID+" ";

html += " "+user.PatientName+" ";

html += " "+user.IdentityCardNo+" ";

html += " ";

html +="删除";

html +="修改";

html += " ";

html += "";

}

//console.log(html);

$("body").innerHTML = html;

}

}

利用这个js代码取不到值,求大神讲解。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1159/viewspace-3134079/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 分开多次结账
请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    126
  • 访问量
    876