Jquery Mobile getJSON 回调未触发

发布于 2024-12-29 12:29:55 字数 1293 浏览 3 评论 0原文

我正为此抓狂。我试图调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如何视而不见 2025-01-05 12:29:55

一些调试提示:

  1. 确保正在调用 getEmployeeList()。将 console.log('getEmployeeList()') 命令放在该函数的顶部。如果它没有被调用,那么我的猜测是 #employeeListPage 不存在(至少在您期望的时候不存在。)
  2. 检查您尝试调用的 URL 是否是您认为的那样这是。记录整个 URL。
  3. 使用 Firebug 查看请求和响应。您能看到正在请求的页面吗?它给出有效的响应吗?如果没有,那么你的成功回调函数将不会被调用。还添加失败回调。

编辑
根据评论 - 似乎 Play 框架本身并不支持 JSONP。我不确定你是否对此有任何控制权。 http://groups.google.com/group/play-framework/browse_thread /线程/253107904a5c98f8

Some debugging tips:

  1. Ensure that getEmployeeList() is being called. Put a 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.)
  2. Check the URL that you are attempting to call is what you think it is. Log the whole URL.
  3. Use Firebug to look at the requests and responses. Can you see the page being requested? Does it give a valid response? If not, then your success callback function will not be called. Add a failure callback as well.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文