2011-07-27 77 views
0

i'm新手,有xhrGet一個問題,它返回空的響應數據。道場xhrGet在道場返回空數據

function test1(){ 
      // Using dojo.xhrGet, as very little information is being sent 
      dojo.xhrGet({ 
       // The URL of the request 
       url: 'http://www.dojotoolkit.org/documentation/tutorials/1.6/ajax/demo/get-content.php', 
       // The success callback with result from server    
       load: test2,     
       // The error handler 
       error: function(errorMessage) { 
        // Do nothing -- keep old content there 
        alert("Error Message: " + errorMessage); 
       } 
      }); 
     } 
     function test2(result, ioArgs){ 
      alert(result); 
      dojo.byId("tContent").innerHTML += result; 
     } 

我debuged此代碼,結果是空的始終。任何人都可以說我,我做錯了什麼?

在此先感謝

低糜

回答

1

我猜這是因爲你的網站是在yourdomain.com,而是你正試圖從dojotoolkit.org獲取數據。由於瀏覽器中的same origin policy(無法請求來自其他域的頁面),此操作無效。嘗試用您自己的域中的某些內容替換dojotoolkit網址。

+0

嗨,我必須從其他網站獲取數據。我現在發現我必須使用「跨站點XHR插件」。我是否正確? – user864980

+0

@ user864980是的,你可能是。您可能還想在JSONP上進行搜索(填充的JSON)。各種技巧取決於您的服務器/服務以及它如何呈現數據。 – Frode

+0

你能給我一個簡單的例子(f.e.加載任何HTTP內容),請。我發現了任何代碼片斷,但它不工作... – user864980