Page 1 of 1

Passing Ajax variable to PHP

Posted: Tue Apr 26, 2011 7:36 am
by zyntrax
Hi i'm wondering if it's possible to pass an Ajax variable to PHP.
Because i'm using a ajax based wysiwyg edit and i would like to pass the variable that contains the edited content to PHP.

Help would be very much appreciated

Re: Passing Ajax variable to PHP

Posted: Tue Apr 26, 2011 9:05 am
by prensil
Refer Ajax.Request or Ajax.Updater method in prototype JavaScript library. You can pass variable using the Form.serialize method or parameters.

Re: Passing Ajax variable to PHP

Posted: Tue Apr 26, 2011 1:34 pm
by CrowderSoup
It depends a little on what JavaScript library/framework you're using, if any. You can definitely pass variables to a PHP script using ajax though, you will just pass them in the $_GET or $_POST of the ajax request.

A little more specificity on whether or not you're using a JavaScript framework/library would help, so we could point you in the right direction.

Re: Passing Ajax variable to PHP

Posted: Mon May 09, 2011 8:40 am
by zyntrax
Hey thanks for the replies. Here's the code i use

Code: Select all

<script type="text/javascript" src="/tinymce/jscripts/tiny_mce/tiny_mce.js">
</script>
<?php
include 'read.php';
?>
<script type="text/javascript">
tinyMCE.init({
    mode : "textareas",
    theme : "advanced"
});
function ajaxLoad() {
    var ed = tinyMCE.get('content');
    ed.setProgressState(1);
    window.setTimeout(function() 
	{
        ed.setProgressState(0);
        ed.setContent('<?php echo $body; ?>');
    }, 3000);
}
function ajaxSave() {
    var ed = tinyMCE.get('content');
    ed.setProgressState(1);
    window.setTimeout(function() 
	{
        ed.setProgressState(0);
        alert(ed.getContent());
    }, 3000);
}
</script>
<form method="post" action="write.php">
    <textarea name="content" style="width:100%">
	</textarea>
</form>

Re: Passing Ajax variable to PHP

Posted: Mon May 09, 2011 12:32 pm
by AbraCadaver

Code: Select all

//write.php
echo $_POST['content'];