Passing Ajax variable to PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zyntrax
Forum Commoner
Posts: 32
Joined: Wed Apr 13, 2011 2:23 am
Location: Sweden

Passing Ajax variable to PHP

Post 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
prensil
Forum Newbie
Posts: 15
Joined: Tue Apr 26, 2011 8:38 am
Location: Ahmedabad
Contact:

Re: Passing Ajax variable to PHP

Post by prensil »

Refer Ajax.Request or Ajax.Updater method in prototype JavaScript library. You can pass variable using the Form.serialize method or parameters.
User avatar
CrowderSoup
Forum Newbie
Posts: 18
Joined: Thu Apr 21, 2011 2:56 pm
Location: Murray, UT

Re: Passing Ajax variable to PHP

Post 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.
zyntrax
Forum Commoner
Posts: 32
Joined: Wed Apr 13, 2011 2:23 am
Location: Sweden

Re: Passing Ajax variable to PHP

Post 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>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Passing Ajax variable to PHP

Post by AbraCadaver »

Code: Select all

//write.php
echo $_POST['content'];
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply