使用Ajax和Jquery设置Iframe的目标?

时间:2011-02-09 09:43:30

标签: php jquery ajax zend-framework iframe

我在点击DIV时使用zend-framework,iframe,ajax和jquery来调用url。

我正在使用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“text”控件转到http://localhost.test.com/public/index/listen-message但结果没有显示在IFRAME中....?

可能存在的问题......?

请提供一些代码,链接和想法......

提前致谢......

3 个答案:

答案 0 :(得分:1)

我想您应该将返回的结果附加到iframe。你的ajac-call ATM在成功函数中什么都不做。

试试

success:function(data){$(“#listenMsg”)。append(data); }

编辑:

我想我的问题是错的。你想动态设置目标,对吗?

然后使用

success:function(data){$(“#”+ $(this).attr('target'))。append(data); } 并将id="listenMsg"添加到您的iframe

    target = $(this).attr('target');
    $('body', window.frames[target].document).append(data);

答案 1 :(得分:1)

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

答案 2 :(得分:1)

+1给出这个答案 - 虽然代码中有错误:

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