Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ajax jquery get调用来填充表_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript Ajax jquery get调用来填充表

Javascript Ajax jquery get调用来填充表,javascript,jquery,ajax,Javascript,Jquery,Ajax,我正在尝试从包含id的url进行web服务get调用。url为http://10.173.143.252:8181/cxf/crm/customerservice/customers/125 url发回一个json响应 {"id":125,"name":"John","password":"password","role":"user","privileges":["SMPP Balance Enquiry","Trigger SMPP Notification"],"status":"acti

我正在尝试从包含id的url进行
web服务
get调用。url为
http://10.173.143.252:8181/cxf/crm/customerservice/customers/125

url发回一个json响应

{"id":125,"name":"John","password":"password","role":"user","privileges":["SMPP Balance Enquiry","Trigger SMPP Notification"],"status":"active"}
我的ajax jQuery代码是:

$(document).ready(function() {
    jQuery.support.cors = true;

    $.ajax(
    {
         type: "GET",
         url: "http://10.173.143.252:8181/cxf/crm/customerservice/customers/125",
         data: "{}",
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         cache: false,
         success: function (data) {
              $.each(data, function () {
                  $("#personDataTable tbody").append("<tr>"+"<td>"+data.id+"</td>"
                                 +"<td>"+data.name+"</td>"
                                 +"<td>"+data.password+"</td>"
                                 +"<td>"+data.role+"</td>"
                                 +"<td>"+data.privileges+"</td>"
                                 +"<td>"+data.status+"</td>"
                                 +"</tr>" )

    //     trHTML += '<tr><td>' + data.id[i] + '</td><td>' + data.name[i] + '</td><td>' + data.password[i] + '</td><td>' + data.role[i] + '</td><td>' + data.privileges[i] + '</td><td>' + data.status[i] + '</td></tr>';
    })
},
    error: function (msg) {

        alert(msg.responseText);
      }
   });
});
$(文档).ready(函数(){
jQuery.support.cors=true;
$.ajax(
{
键入:“获取”,
url:“http://10.173.143.252:8181/cxf/crm/customerservice/customers/125",
数据:“{}”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
cache:false,
成功:功能(数据){
$。每个(数据、函数(){
$(“#personDataTable tbody”).append(“+”+数据.id+”)
+“”+数据。名称+“”
+“”+数据。密码+“”
+“”+数据。角色+“”
+“”+数据权限+“”
+“”+数据。状态+“”
+"" )
//trHTML+=''+data.id[i]+''+data.name[i]+''+data.password[i]+''+data.role[i]+''+data.privileges[i]+''+data.status[i]+'';
})
},
错误:函数(msg){
警报(msg.responseText);
}
});
});
我的html看起来像:

<table class="table table-hover" id="personDataTable">
    <tr>
        <th>id</th>
        <th>name</th>
        <th>password</th>
        <th>role</th>
        <th>privileges</th>
        <th>status</th>
    </tr>
</table>

身份证件
名称
密码
角色
特权
地位

我的方法对我来说很合适。在一次重新加载时,表中填充了6行相同数据的原因可能是什么。是的,我已经浏览了
google

中的许多其他链接,您必须首先解析json响应才能使用它

parsedData = JSON.parse(data);
将此行
$替换为每一行(data.id,function(i,item){

$.each(parsedData.id, function (i, item) {
var数据={
“id”:125,
“姓名”:“约翰”,
“密码”:“密码”,
“角色”:“用户”,
“特权”:[“SMPP余额查询”,“触发SMPP通知”],
“状态”:“活动”
}
for(var输入数据){
console.log(数据[键])
}

身份证件
名称
密码
角色
特权
地位

您在控制台中遇到了什么错误?
$。每个(data.id
?应该是
数据吗?$。每个(data.id,function(i,item){改为使用$。每个(data,function(i,item){正如您提到的响应内容,您不必使用$。每个都要迭代,它是一个单独的对象,所以只需尝试像data.id这样访问它,除非您明确告诉jquery您将加载JSON响应。他将自动解析它并在回调函数中提供一个对象。这里就是这样。您可以看到“数据类型”'设置为'json',因此数据将是一个表示已解析json的对象。抱歉,我不清楚。我正在尝试使用
http://10.173.143.252:8181/cxf/crm/customerservice/customers/125
web服务。