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
Passing Ajax variable to PHP
Moderator: General Moderators
Re: Passing Ajax variable to PHP
Refer Ajax.Request or Ajax.Updater method in prototype JavaScript library. You can pass variable using the Form.serialize method or parameters.
- CrowderSoup
- Forum Newbie
- Posts: 18
- Joined: Thu Apr 21, 2011 2:56 pm
- Location: Murray, UT
Re: Passing Ajax variable to PHP
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.
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
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>
- 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
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.