2013-01-02 62 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