Jquery Mobile getJSON 回调未触发
我正为此抓狂。我试图调用 getJSON 并且回调函数从未被触发。我尝试添加警报以及萤火虫调试,但回调从未发生。
服务响应显示 JSON 字符串,因此不确定出了什么问题。有什么指点吗?
这是我调用 Play 框架服务的代码:
var serviceURL = "http://localhost:9000/signup/";
var employees;
$('#employeeListPage').bind('pageinit', function(event) {
$.mobile.allowCrossDomainPages = true;
getEmployeeList();
});
function getEmployeeList() {
$.getJSON(serviceURL + 'getemployees?callback=?', function(data) {
alert(data);
$('#employeeList li').remove();
employees = data.items;
$.each(employees, function(index, employee) {
$('#employeeList').append('<li><a href="employeedetails.html?id=' + employee.id + '">' +
'<img src="pics/' + employee.picture + '"/>' +
'<h4>' + employee.firstName + ' ' + employee.lastName + '</h4>' +
'<p>' + employee.title + '</p>' +
'<span class="ui-li-count">' + employee.reportCount + '</span></a></li>');
});
$('#employeeList').listview('refresh');
});
}
播放服务返回一个 json 字符串。
有人看到我做错了什么吗?为什么警报从未执行?
I am pulling my hair out with this. I am trying to invoke a getJSON and the callback function is never triggered. I tried adding an alert as well as firebug debug but the callback never happens.
The service response shows a JSON string so not sure what is going wrong. Any pointers?
Here is my code which calls a Play Framework service:
var serviceURL = "http://localhost:9000/signup/";
var employees;
$('#employeeListPage').bind('pageinit', function(event) {
$.mobile.allowCrossDomainPages = true;
getEmployeeList();
});
function getEmployeeList() {
$.getJSON(serviceURL + 'getemployees?callback=?', function(data) {
alert(data);
$('#employeeList li').remove();
employees = data.items;
$.each(employees, function(index, employee) {
$('#employeeList').append('<li><a href="employeedetails.html?id=' + employee.id + '">' +
'<img src="pics/' + employee.picture + '"/>' +
'<h4>' + employee.firstName + ' ' + employee.lastName + '</h4>' +
'<p>' + employee.title + '</p>' +
'<span class="ui-li-count">' + employee.reportCount + '</span></a></li>');
});
$('#employeeList').listview('refresh');
});
}
The play service returns a json string.
Anyone see what am i doing wrong? why is the alert never executed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些调试提示:
console.log('getEmployeeList()')
命令放在该函数的顶部。如果它没有被调用,那么我的猜测是#employeeListPage
不存在(至少在您期望的时候不存在。)编辑
根据评论 - 似乎 Play 框架本身并不支持 JSONP。我不确定你是否对此有任何控制权。 http://groups.google.com/group/play-framework/browse_thread /线程/253107904a5c98f8
Some debugging tips:
console.log('getEmployeeList()')
command right at the top of that function. If it's not being called, then my guess would be that#employeeListPage
does not exist (at least, not when you are expecting it to.)EDIT
Based on comments - seems that the Play framework does not natively support JSONP. I'm not sure whether you have any control over that. http://groups.google.com/group/play-framework/browse_thread/thread/253107904a5c98f8