2011-10-08 17 views
0

我試過了jQuery get函數並編碼如下。我的下面的代碼有什麼問題?它不工作。在jQuery中將數據加載到DIV中

<style type="text/css"> 
<!-- 
#Layer1 { 
    position:absolute; 
    width:200px; 
    height:115px; 
    z-index:1; 
} 
--> 
</style> 
<div id="Layer1"> </div> 
<script type="text/javascript"> 
    jQuery.get('http://google.com/', null, function(data) 
    {$('#Layer1').append(data); 
}, 'html'); 
</script> 
+0

如果你真的使用'google.com',那麼它的一個跨域請求,這不應該工作。 – Usman

+0

我試過偶'jQuery.get('test.html',null,function(data)'但是沒有用:( –

回答

2

您正試圖從a different origin獲取數據,這是出於安全原因而不允許的。

+0

我試過連jQuery.get('test.html',null,function(data)'但是沒有用:( –

+0

)如果你想從不同的來源獲取數據,唯一的選擇是JSONP(http://en.wikipedia.org/wiki/JSONP) – topek

+0

試試$ .get('test.html',function(數據)...);不作爲第二參數爲空 – topek

相關問題