【问题标题】:Using JQuery.Ajax to change content in other file使用 JQuery.Ajax 更改其他文件中的内容
【发布时间】:2012-04-05 08:50:02
【问题描述】:

我在我的应用程序中使用了一个 iFrame,它允许用户上传一个 CSV 文件,该文件包含有关要添加到数据库中的新国家/地区的信息。我想要的是,一旦 CSV 文件被处理到数据库中,显示数据库中当前国家/地区的现有选择框应该使用新添加的 CSV 文件条目进行更新。

我是 ajax 调用之类的

    $(document).ready(function(){
    jQuery.ajax({
        type: "POST",
        url: "get_all_countries.php",
        data: '',
        cache: false,
        success: function(response)
        {
            $("#all_countries_select_box").html("<select name='all_countries' id='all_countries' MULTIPLE size='8' style='min-width:250px;'>"+response+"</select>");
        }
    });
});

我唯一的问题是 id 'all_countries_select_box' 在另一个名为 'manage_countries.php' 的 PHP 文件中。有没有办法从 iFrame (upload.php) 中的文件更改该文件的内容。如果没有,最好的解决方案是什么

【问题讨论】:

    标签: php jquery iframe


    【解决方案1】:

    如果你想从 iframe 中访问父窗口,你应该使用 window.parent

     success: function(response)
        {
            var parentJQuery = window.parent.jQuery;
            parentJQuery("#all_countries_select_box").html("<select name='all_countries' id='all_countries' MULTIPLE size='8' style='min-width:250px;'>"+response+"</select>");
        }
    

    如果您要修改的文件位于 iframe 中,您应该这样做

     success: function(response)
        {
    
            $('#idoftheiframe').contains().find("#all_countries_select_box").html("<select name='all_countries' id='all_countries' MULTIPLE size='8' style='min-width:250px;'>"+response+"</select>");
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-10
      • 2014-06-21
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多