我想使用ajax从服务器解析一些数据: projects.js:
$("#Projects").click(function(){
$.ajax({
url: "http://192.168.0.49:1080/plw6.2/admin/OPX2ADMIN/192.168.0.49:9400/odata/project?%24select=name%2Cstatus",
type: "GET",
dataType: 'json',
//Success of Authorization
success: function(result){
var tr;
var str = JSON.stringify(result);
obj = JSON.parse(str);
for(var i = 0; i < obj.value.length; i++) {
tr = $('<tr/>');
tr.append("<tr><td class=\"project_title\">" + obj.value[0].name + "</td></tr>");
tr.append("<tr><td class=\"project_status\">" + obj.value[0].status + "</td></tr>");
tr.append("<tr><td class=\"project_date\">" + obj.value[0].real_start + "</td></tr>");
$('.project_info').append(tr);
}
},
//Failure of authorization
error: function(jqXHR, status, errorThrown) {
alert("error");
}
});
});
Projects.html:
<div class="project_info">
<table>
<tbody>
<tr>
<td class="project_title">Project1</td>
</tr>
<tr>
<td class="project_status">Active</td>
</tr>
<tr>
<td class="project_date">03/2017-05/2018</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript" src="./js/projects.js"></script>
我无法从服务器获取数据,但服务器的路径是正确的。我该如何解决?
答案 0 :(得分:0)
从服务器返回什么数据?将console.log(result)置于成功()
您需要允许PhoneGap使用allow-intent参数访问外部服务器...请参阅https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/
所以...你的HTML表格不正确(没有表格/表格)