jQuery getJSON request returning empty on a valid request

我的未来我决定 提交于 2019-12-05 12:31:17

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);
  }
});

Or you simply change the url a bit. From

http://ax.phobos.apple.com.edgesuite.net/.../wa/wsSearch"

to

http://ax.phobos.apple.com.edgesuite.net/.../wa/wsSearch?callback=?"

And keep using $.getJSON instead of switching to $.ajax

From the jQuery.getJSON documentation

If the URL includes the string "callback=?" in the URL, the request is treated as JSONP instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!