jQuery getJSON请求在有效请求上返回空 [英] jQuery getJSON request returning empty on a valid request

查看:88
本文介绍了jQuery getJSON请求在有效请求上返回空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Apple的iTunes JSON服务中获取一些JSON.该请求很简单: http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsSearch?term=jac&limit=25

I'm trying to grab some JSON from Apple's iTunes JSON service. The request is simple: http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsSearch?term=jac&limit=25

如果您在浏览器中访问该URL,您将看到一些格式良好(由jsonlint.com备份)的JSON.但是,当我使用以下jQuery发出请求时,请求什么都找不到:

If you visit the URL in your browser you will see some well-formed (backed up by jsonlint.com) JSON. When I use the following jQuery to make the request, however, the request finds nothing:

        $("#soundtrack").keypress(function(){
            $.getJSON("http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsSearch",{'term':$(this).val(), 'limit':'25'}, function(j){              
                var options = '';
                for (var i = 0; i < j.results.length; i++) {
                    options += '<option value="' + j.results[i].trackId + '">' + j.results[i].artistName + ' - ' + j.results[i].trackName + '</option>';
                }
                $("#track_id").html(options);
            });
        });

Firebug看到了请求,但只收到一个空响应.

Firebug sees the request, but only receives an empty response.

在这里,我将尽力解决所有问题,感谢您的帮助.您可以在此处查看脚本: http://rnmtest.co.uk/gd/drives_admin/add_drive (音轨输入框位于页面底部).

Any help would be appreciated here, as I'm at my whits end trying to solve it. You can view the script here: http://rnmtest.co.uk/gd/drives_admin/add_drive (soundtrack input box is at the bottom of the page).

谢谢

推荐答案

为了执行跨域请求,您将需要使用JSONP.这可能会帮助:

In order to do cross-domain requests, your going to need to use JSONP. This may help:

$.ajax({
  url: "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsSearch",
  dataType: 'jsonp',
  data: {'term':$(this).val(), 'limit':'25'}, 
  success: function(j){              
    var options = '';
    for (var i = 0; i < j.results.length; i++) {
      options += '<option value="' + j.results[i].trackId + '">' + j.results[i].artistName + ' - ' + j.results[i].trackName + '</option>';
    }
    $("#track_id").html(options);
  }
});

这篇关于jQuery getJSON请求在有效请求上返回空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆