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.