有人可以帮我使用 livestream 的 api 发出跨域 xml 请求吗?
我正在尝试使用 livestream 非常有用的移动 api,位于 http://www.livestream .com/userguide/?title=Mobile_API#Requesting_a_mobile_stream 发出 xml 请求。我感兴趣的是 isLive 响应值。我正在尝试使用像这样的ajax请求
$.ajax({
type: "GET",
url: "http://xproshowcasex.channel-api.livestream-api.com/2.0/getstream",
datatype: "xml",
success: function(xml){
//this is where I need help. This is what I would like to happen
if (isLive == true) {
//perform action
}
else {
//perform other action
}
我正在使用 http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/ 发出跨域 xml 请求。谁能告诉我这是否是实现这一目标的最有效方法?我还没能让它发挥作用。当我运行 console.log(xml) (这可能不正确)时,JS 控制台显示 objectObject,我认为这意味着我需要解析数据?如果有人能花时间解释这一点,我会很高兴。非常感谢。
I'm trying to use livestream's extremely helpful mobile api found at http://www.livestream.com/userguide/?title=Mobile_API#Requesting_a_mobile_stream to make an xml request. All I am interested in is the isLive response value. I am trying to use an ajax request like this
$.ajax({
type: "GET",
url: "http://xproshowcasex.channel-api.livestream-api.com/2.0/getstream",
datatype: "xml",
success: function(xml){
//this is where I need help. This is what I would like to happen
if (isLive == true) {
//perform action
}
else {
//perform other action
}
I am using the plugin found at http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/ to make cross domain xml requests. Can anyone tell me if this is the most effective way to accomplish this? I haven't been able to get it to work. When I run the console.log(xml) (which probably isn't right) the JS console shows objectObject, which I think means I need to parse the data? I would love it if someone could take the time to explain this. Thanks so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您很接近,您链接到的帖子基本上描述了使用通过 YQL (您可以查看源代码以了解到底发生了什么)。您可以删除该插件,并使用 jQuery 通过常规 JSONP 请求完成相同的操作:
基本上,此函数的作用是调用 Yahoo 的查询 api 并运行一个查询。当响应返回时,返回的脚本将调用 jQuery 提供的回调函数(这就是 JSONP 成为可能的原因)。
您使用的查询(在
q
参数中指定)是针对 XML Feed 的,因此您需要使用select * from xml
来检索数据。然后,您可以告诉 Yahoo 以 JSON 格式提供结果(我建议使用此格式而不是 XML;XML 是命名空间的)。现在,当您调用此函数时:
回调函数接收通过 YQL 检索的 JSON 数据并查找
isLive
属性。示例: http://jsfiddle.net/andrewwhitaker/YAGvd/
You are close, the post you linked to basically describes page-scraping using a cross-domain request that goes through YQL (You can peek at the source to see exactly what's going on). You can cut out the plugin and accomplish the same thing with a regular JSONP request with jQuery:
Basically what this function does is call Yahoo's query api with a query to run. When the response comes back, the script returned calls a callback function that jQuery supplies (this is what makes JSONP possible).
The query you're using (specified in the
q
parameter) is against an XML feed, so you need to useselect * from xml
to retrieve the data. You can then tell Yahoo to give you the result in JSON format (I would recommend using this instead of XML; the XML was namespaced).Now, when you call this function:
The callback function receives the JSON data retrieved via YQL and finds the
isLive
property.Example: http://jsfiddle.net/andrewwhitaker/YAGvd/