父母div在fancybox关闭后不会更新

时间:2014-07-22 16:18:59

标签: javascript jquery fancybox

我有一个功能正常的Fancybox表单,可以从MySQL中删除数据。我希望它在关闭时刷新特定的父页面DIV。

涉及的JavaScript:

function ajaxrequest(php_file, purpose, var1, var2, var3, var4, var5, var6, var7, var8, where) {
    var request = getXMLHTTP();     // call the function for the XMLHttpRequest instance

    // create pairs index=value with data that must be sent to server
    var the_data = 'purpose='+purpose+'&var1='+var1+'&var2='+var2+'&var3='+var3+'&var4='+var4+'&var5='+var5+'&var6='+var6+'&var7='+var7+'&var8='+var8;

    request.open("POST", php_file, true);           // set the request

    // adds  a header to tell the PHP script to recognize the data as is sent via POST
    request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    request.send(the_data);     // calls the send() method with datas as parameter

    // Check request status
    // If the response is received completely, will be transferred to the HTML tag with tagID
    request.onreadystatechange = function() {
        if (request.readyState == 4) {
            window.parent.document.getElementById(where).innerHTML = request.responseText;
        }
    }
}

function done_with_msg() {
    ajaxrequest('include/ajaxprocess.php', 'refresh', 'Messages', '',  '',  '',  '', '',  '',  '', 'content2');
    javascript:parent.jQuery.fancybox.close();
}

在Fancybox中:

<button onclick="done_with_msg();">UPDATE</button>

函数ajaxrequest是分开的,因为我在网站的其他区域使用它(工作完美)。对于这个问题,我正在删除消息DIV中的消息线程,并且希望仅在删除完成时刷新消息DIV。

1 个答案:

答案 0 :(得分:0)

如果fancybox打开iframe,则iframed页面中可能不存在函数ajaxrequest()done_with_msg(),但是在父页面中。

如果是这种情况,您必须按照this post中所述调用父页面中的函数,如:

<button onclick="parent.done_with_msg();">UPDATE</button>