2010-06-18 47 views
0

當從一個博客加載div到另一個博客(在localhost上)時,此代碼可以在localhost上正常工作,但是當嘗試從互聯網上的博客加載到另一個博客時localhost),它不起作用,可能是什麼問題?下面是代碼。Jquery ajax將Web服務器的div內容加載到本地服務器

<?php 

$urlPage = 'http://www.somepage.com/'; //dont work 

//$urlPage = 'http://localhost/myBlog1/'; //work fine 
?> 

<script type="text/javascript"> 

    var addr; 

    jQuery(document).ready(function($){ 

     addr = '<?php echo $urlPage; ?>'; 

     $.ajax({ 
      url: addr, 
      success: function(html) { 
       $(".divToLoadContent").append($(html).find('#sidebar ul').html()); 
      } 
     }); 
     return false; 
    }); 
</script> 

<style type="text/css"> 
    .divToLoadContent { 
     margin:0px; 
     border: 1px solid lime; 
     width: 100%; 
    } 
</style> 

<div class="divToLoadContent"> 
</div> 
+1

你不能讓一個AJAX請求到遠程域:)不要讓原始的HTML反正JSONP你雖然可以。 – 2010-06-18 09:49:45

+0

我不知道:) tnx,我只是在本地主機上測試:)我也嘗試在互聯網BTW 2博客,仍然沒有。我會看看現在jsonp的例子:) – user147 2010-06-18 10:10:20

+0

仍然不能得到這個東西的工作,可以幫助我這個?我想從一個博客拉div標籤到另一個? – user147 2010-06-18 11:42:50

回答