2013-01-02 38 views
1

我尝试发送到httpbin要求与prototype.js中发送Ajax请求,并得到了prototype.js中响应

我的代码:

function loadTest() 
{ 
    new Ajax.Request('http://httpbin.org/get', { method:'get', 
     // success request 
     onSuccess: 
      function(transport) { 
       alert("Success! \n\n" + transport.status); 
     }, 
     // fail request 
     onFailure: 
      function() { 
       alert('Something went wrong...'); 
      } 
    }); 
} 

执行后我得到:Success!transport.status = 0

为什么?我怎样才能正确发送请求,并得到与prototype.js的回应?

谢谢。

回答

2

你的代码没有什么错,除了一件事情,你不能跨域XMLHttpRequest

您应该使用启用CORS的代理。

另一种选择是JSONP请求。

正如我所看到的,他们都不适用于httpbin