I'll try to explain as best as possible what's going:
I have a drag & drop page for building newsletters. When an item is dragged and then dropped, it calls an AJAX request to get the full content of the item from the database and display it into a lightbox. The user can then accept or cancel the opperation. Here's where the problem happens... If the user accepts the content, it then does another AJAX call to retrieve the data, set a session variable, and then put it into an XML format for return. The javascript then parses the XML, does misc. functions and puts it into the HTML of the template. Here's the code for generating the XML:
Code: Select all
$_SESSION['savedContent'][$_GET['divReceive']]['InsertID'] = $dataId; // $dataId is the id of the item pulled out of the database
.... // misc irrelavent code
header("Content-type: text/xml");
ob_start();
print "<?xml version=\"1.0\"?>\n\r";
print "<response>\n\r";
foreach($response as $type=>$content) {
print " <{$type}>\n\r";
if(is_array($content)){
foreach($content as $subtype=>$subcontent){
print " <{$subtype}>\n\r";
print " <![CDATA[\n\r";
print " {$subcontent}\n\r";
print " ]]>\n\r";
print " </{$subtype}>\n\r";
}
}else{
print " <![CDATA[\n\r";
print " {$content}\n\r";
print " ]]>\n\r";
}
print " </{$type}>\n\r";
}
print "</response>";
echo ob_get_clean();
The kicker is that every subsequent drag, drop, accept instance works just fine. It's just the VERY FIRST time it doesn't...
The ajax call is hitting the same page as the drag and drop interface itself (index.php), but I have a check to see if it's an ajax call. If it is, include the ajax_functions.php file and exit. I do this so I can make use of my various includes (configurations, db connections, etc.). Shown below:
Code: Select all
if(isset($_POST['ajax']) || isset($_GET['ajax'])){
include 'ajax_functions.php';
exit;
}else{
// clear previous template session stores
// This is so when the page is refreshed or a new newsletter is being created, it resets all the previous session variables so no confusion is caused.
if(isset($_SESSION['savedContent'])) unset($_SESSION['savedContent']);
}
I've stated above that the ajax call is hitting the same page as the drag & drop itself, but I have moved everything onto a separate page completely way from index.php and it still happens.
One question that I can not come up with an answer for is: is the header() bypassing my exit somehow? I've done tests that all lead to no and none of the HTML is being returned either, but still other parts of the script are being executed that should not be.
I really hope someone can help me.
Thank you in advance.