2011-02-09 21 views
2

我正在使用zend-framework,iframe,ajax和jquery在單擊DIV時調用url。使用Ajax和Jquery設置Iframe的目標?

我使用的iframe如下

<iframe src="http://localhost.test.com/public/index/listen-message" name="listenMsg" height="120" width="600"> 
          <p>Your browser does not support iframes.</p> 
         </iframe> 

我用以下爲DIV

<div target="listenMsg" class="text" id="<?php echo $row['id']; ?>"> 
...... 
</div> 

而jQuery的我寫下面的代碼的代碼.....

$(".text").click(function() 
{ 
    var clickedDiv = $(this).attr("id"); 

    var id=$(this).attr("id"); 

     $.ajax({ 
     type: "POST", 
     url: "http://localhost.test.com/public/index/listen-message", 
     data: id, 
     success: function(data){ 

     } 
     }); 
     return false; 
}); 

但是,當我點擊DIV「文本」控件去http://localhost.test.com/public/index/listen-message,但結果不顯示在IFRAME ....?

什麼可能是可能的問題....?

請提供一些代碼,鏈接和想法......

在此先感謝......

回答

1

+1這個答案 - 雖然在代碼中的錯誤:

$('iframe[name="listenMsg"]').contents().find("body").html("your message"); 
1

,我想你應該返回的結果追加到iframe。 ATM您的ajac-call在成功功能中沒有做任何事情。

試試看

成功:功能(數據){$( 「#listenMsg」)追加(數據)。 }

編輯:

我想我得到了你的問題是錯誤的。你想動態設置目標,對嗎?

然後使用

成功:功能(數據){$( 「#」 + $(本).attr( '目標'))附加(數據); } 並添加 id="listenMsg"到iframe

target = $(this).attr('target'); 
    $('body', window.frames[target].document).append(data); 
1
$('iframe[name="listenMsg"').contents().find("body").html("your message");