Ajax和REST:是否可以将ajax请求发送到REST服务以接收响应? [英] Ajax And REST: Can I send an ajax request to a REST service to recieve response?

查看:56
本文介绍了Ajax和REST:是否可以将ajax请求发送到REST服务以接收响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用mootools和SqueezBox类来处理对RESTful服务的请求.我不想使用任何服务器端脚本.我正在使用AJAX.我使用GET方法将请求发送到以下网址. http://www.idevcenter.com/api/v1/links/links-upcoming.json 但我收到404错误.是因为跨站点脚本编写吗?这是我的代码:

I want to use mootools and SqueezBox class to handle a request to a RESTful service. I don't want to use any server-side script. I am using AJAX. I send a request to the following url using GET method. http://www.idevcenter.com/api/v1/links/links-upcoming.json but I receive a 404 error. Is it because cross-site scripting? here is my code:


SqueezeBox.initialize({handler:'url',ajaxOptions:{method:'GET'}});
$('a.modal').addEvent('click',function(e){
    new Event(e).stop();
    SqueezeBox.fromElement($('a.modal'));
});

在Firebug控制台中,有时会显示"aborted",有时会显示"404".这有什么问题?

In Firebug console, sometimes 'aborted' is shown and sometimes '404'.what is wrong with that?

推荐答案

XMLHttpRequest受相同起源的约束政策;如果运行JavaScript的文档与您要调用的服务的来源不同,出于安全原因,将不允许该调用.

XMLHttpRequest is subject to the Same Origin Policy; if the document your JavaScript is running within is not from the same origin as the service you're trying to call, the call will be disallowed for security reasons.

现在有一个针对跨域资源共享的拟议标准.您尝试使用的服务可能支持该服务;如果是这样,则可以使用实现CORS的浏览器(Firefox和Chrome的最新版本,以及其他一些浏览器)来工作.IE8 支持它,但要求您做额外的工作.

There is now a proposed standard for cross-origin resource sharing to address this. It may be that the service you're trying to use supports it; if so, using a browser that implements CORS (recent versions of Firefox and Chrome do, as do some others) may work. IE8 supports it but requires that you do extra work.

这篇关于Ajax和REST:是否可以将ajax请求发送到REST服务以接收响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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