0

I have a functioning Fancybox form that deletes data from MySQL. I wish it to refresh a specific parent page DIV upon closing.

The JavaScript involved:

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();
}

In the Fancybox:

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

Function ajaxrequest is separated because I use it (works perfect) in other areas of the site. For this issue I am deleting a message thread in the Message DIV and wish to refresh ONLY the Message DIV with the deletion completed.

Regent
  • 5,142
  • 3
  • 21
  • 35
  • is the fancybox opening as iframe? because you are closing as `parent.jQuery.fancybox.close()` if so, the ajax call `ajaxrequest()` exists in the parent but not inside the iframe. If that is the case, check http://stackoverflow.com/a/2161402/1055987 – JFK Jul 22 '14 at 16:52
  • yes fancybox is opening as an iFrame. checked what you referred to and worked lke a charm. now post an answer so I can give you credit lol – AlbertaXChange Jul 22 '14 at 17:00

1 Answers1

0

If fancybox opening an iframe, the functions ajaxrequest() and done_with_msg() may not exist in the iframed page but in the parent page.

If that is the case, you have to call the function(s) in the parent page as described in this post like :

<button onclick="parent.done_with_msg();">UPDATE</button>
Community
  • 1
  • 1
JFK
  • 40,963
  • 31
  • 133
  • 306