jQuery ajax调用无响应 [英] No response from jQuery ajax call

查看:319
本文介绍了jQuery ajax调用无响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今晚在这个问题上苦苦挣扎了很长时间,并且在寻找答案时没有发现任何有用的东西.这可能很简单.

I've been struggling with this for way too long tonight, and I haven't found anything useful when searching for answers. It's probably very simple.

我正在尝试通过使用jQuery进行AJAX调用来使用Spotify元数据API加载数据. 在浏览器中运行此请求就可以了: http://ws.spotify.com/search/1/track?q= foo 但是,当我尝试使用jQuery加载相同的请求时,没有任何响应.我尝试了不同的contentTypes和dataTypes,但我不知道出了什么问题!

I'm trying to load data using the Spotify Metadata API by doing AJAX calls with jQuery. Running this request in a browser works just fine: http://ws.spotify.com/search/1/track?q=foo But when I try to load the same request using jQuery I get nothing in response. I've tried different contentTypes and dataTypes, but I can't figure out what's wrong!

代码很简单:

$.ajax({ 
    url: "http://ws.spotify.com/search/1/track",
    data: "q=foo",
    success: function(xml){
        // do stuff...
    },
    contentType: "application/xml",
    dataType: "xml"
});

如果我保存在浏览器中运行查询时返回的XML,并将该文件作为$ .ajax-request中的url参数加载,则一切正常,因此我认为它与格式有关.

If I save the XML returned when running the query in the browser, and loading that file as the url-parameter in the $.ajax-request, everything works just fine, so I guess it has something to do with the format.

Spotify元数据API的文档可能有用,但是我不知道自己该怎么做.

The documentation for the Spotify Metadata API might be useful, but I can't figure out what I could be doing wrong.

推荐答案

您无法进行跨域Ajax调用(在大多数浏览器中).由于Spotify API端点尚不支持 jsonp ,那么您将必须创建一个服务器端代理,该代理将xml反馈回您的页面.

You cannot make a cross domain ajax call (in most browsers). Since the spotify api end point does not yet support jsonp then you will have to make a server side proxy which will feed the xml back to your page.

这篇关于jQuery ajax调用无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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