我有一个以以下 Json 格式返回的网络服务
{
"data": [
{
"id": 61,
"fullName": "second,first",
"firstName": "second",
"ownerId": 4,
"emailId": "skmvilla@gmail.com",
"lastName": "first",
"isDeleted": "N",
"smodifyDate": "July2012",
"statusName": "New",
"orgId": 20
},
{
"id": 62,
"fullName": "second,first",
"firstName": "second",
"ownerId": 4,
"emailId": "skmvilla@gmail.com",
"lastName": "first",
"isDeleted": "N",
"smodifyDate": "July2012",
"statusName": "New",
"orgId": 20
}
],
"vprospectMonthlySum": null,
"vProspectMonthly": null,
"vProspectCount": null
}
我希望在 HTML 表格中显示上述数据。因此,我对其余服务 URL 进行了 ajax 调用,并且它还返回了我的 firebug 工具中的数据。
我无法以 html 形式打印上述数据。下面是我的html代码
<html>
<head>
<title>Itaxibook</title>
<h2>Itaxi</h2> </br>
<div class="table" id="tab1">
<table class="basic-table" id="karthi">
<thead>
<tr>
<td><label >Id</label></td>
<td align="left"><input type="text" id="id" class="medium" name="" value=""></td>
</tr>
<tr>
<td><label>OrgId</label></td>
<td align="left"><input type="text" id="orgId" class="medium" name="" value=""></td>
</tr>
<tr>
<td><label>FullName</label></td>
<td align="left"><input type="text" id="fullName" class="medium" name="" value=""></td>
</tr>
<tr>
<td><label >EmailId</label></td>
<td align="left"><input type="text" id="emailId" class="medium" name="" value=""></td>
</tr>
<tr>
<td><label>ModifyDate</label></td>
<td align="left"><input type="text" id="smodifyDate" class="medium" name="" value=""></td>
</tr>
</thead>
</table>
</div>
</form>
</head>
</html>
</html>
下面是我的 AJAX 代码
$.ajax({
type: "GET", //GET or POST or PUT or DELETE verb
url: "http://88.80.223.163:8080/lumiin-service/lumiin/control/vprospects", // Location of the service
//contentType: "application/json",
//data: JSON.stringify(params),
dataType: "json",
success: function (data) {//On Successfull service call
var txtStr = '<table class="datatable"><title="Prospect"><thead><tr> <th>Id</th> <th>OrgId</th> <th>FullName</th> <th>EmailId</th> <th>ModifyDate</th> </tr></thead><tbody></title>';
for(var i = 0; i < data.length; i++) {
txtStr += '<tr class="gradeA"> <td><a class="edit_row" href="#tab2" onclick="showDetails(\''+data[i].id+'\');">'+data[i].id+'</a></td> <td>'+data[i].orgId+'</td> <td>'+data[i].fullName+'</td> <td>'+data[i].emailId+'</td> <td>'+data[i].smodifyDate+'</td> </tr>';
}
txtStr += '</tbody></table>';
$("#tab1").html(txtStr);
document.getElementById('karthi').innerHTML = txtStr;
},
error: ServiceFailed// When Service call fails
});
我收到错误,因为类型错误 document.getelementbyId 为 null
任何帮助都感激不尽
谢谢卡西