Page 2 of 2

Posted: Mon Jan 29, 2007 9:40 pm
by aluminumpork
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


The code you posted there is actually almost the identical way I'm doing it.
Except instead of attached ?xmlrequest as a get, I'm adding it as a POST.

So:

[syntax="javascript"]
function startRequest(){
   ...
   var postText = 'variable=data';
   postText += 'javascript=yes';
   xmlHttp.open("POST","bar.php",true);
   xmlHttp.send(postText);
}
Except "bar.php" looks something like this:[/syntax]

Code: Select all

<?php
header('Cache-Control: none');
if($_POST['javascript']=='yes'){
   header('Content-Type: text/xml');
}

// DO MYSQL STUFF

if($_POST['javascript']=='yes'){
   echo "<results>";
   echo "<content>" . $content_data . "</content>";
   echo "</results>";
} else {
   header('Location: originalPage.php?variable=' . $data);
}

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Jan 29, 2007 9:43 pm
by superdezign
Well maybe this is a personal preference of mine, but I say you use a session. If you want to use a post variable because it only lasts for one page, unset() the session variable when you're done with it.

Posted: Mon Jan 29, 2007 9:52 pm
by aluminumpork
Yeah, I was thinking about using a session, and I still may end up doing that. I was just afraid that it may not always work as well. That's what I will probably end up using, thanks for you help everyone!

Posted: Tue Jan 30, 2007 4:36 am
by volka
I must be missing the point. Redirect? Session? What for?
The request tells you what the data is supposed to look like. Let the script render the data accordingly and you're done

Code: Select all

<?php
$data = fechData($_POST);
if ( isset($_POST['javascript']) && 'yes'===$_POST['javascript']) {
	ajaxdata($data);
}
else {
	htmldata($data);
}
?>