嗯...我試圖在jQuery中使用php變量,在我的edit.php中:我想用jquery來顯示php變量,使用「rel」屬性,但它給了我變量的「名稱」,而不是它的內容。如何顯示從jQuery的PHP變量「內容」? (它顯示了我的名字本身,而不是它的內容)
我使用PHP來檢索XML文件中的文本:(編輯:一按就提交不更新的內容,但2次點擊辦)
/* 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');
}
?>
(文本只是所示一個textarea,在這裏我只是把PHP變量) 然後使用jQuery顯示從PHP變量的內容:(編輯與數組對象:)
$('#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;
})
如果我雙擊提交這份工作,如果我只是點擊一次,文本不會更新...我有點困惑與th在
感謝您的幫助
相關:http://stackoverflow.com/q/2145727/212218 – 2011-10-31 23:02:51