Hmm… i’m trying to use a php variable in jquery, in my edit.php : i’d like to use jquery to show the php variable, using the “rel” attribute, but it gives me the “name” of the variable, not its content.
i’m using php to retrieve the text from the xml file : (edit : one click on submit does not update the text, but 2 clicks do)
/* READ */
$dom = new DomDocument();
$dom->load('edition.xml');
$_home = $dom->getElementsByTagName('home')->item(0);
$home = $_home->firstChild->nodeValue;
$_rhizo = $dom->getElementsByTagName('rhizo')->item(0);
$rhizo = $_rhizo->firstChild->nodeValue;
$_disco = $dom->getElementsByTagName('disco')->item(0);
$disco = $_disco->firstChild->nodeValue;
/* array */
$rels = array('home' => $home,
'rhizo' =>$rhizo,
'disco' =>$disco);
echo '<script>var rels = ' . json_encode($rels) . '</script>';
/* WRITE */
if ( isset($_POST['cache']) ){
if ( isset($_POST['home']) ){
$home = stripslashes($_POST['home']);
$_home->firstChild->nodeValue = $home;
}
if ( isset($_POST['rhizo']) ){
$rhizo = stripslashes($_POST['rhizo']);
$_rhizo->firstChild->nodeValue = $rhizo;
}
if ( isset($_POST['disco']) ){
$disco = stripslashes($_POST['disco']);
$_disco->firstChild->nodeValue = $disco;
}
$dom->save('edition.xml');
}
?>
(the text is simply shown in a textarea, where i just put the php variable)
then i use jquery to show the content from the php variable : (edit with the array object : )
$('#left a').bind('click', function(){
var text_from_link = $(this).text();
var rel = $(this).attr('rel');
$('#textarea1').attr('name', rel);
$('#textarea1').text(rels[''+rel+'']);//output is "$home" for example, which will retrieve the "home" part from the xml
return false;
})
And this works if i double click on submit, if i just click once, the text is not updated… i’m a bit confused with that
Thanks for your help
You need to do an ajax call to do that.
Or you can write a javascript object in your HTML:
Then access them with javascript: