0
我想使用單個DIV節,讓遠程PHP腳本根據它的調用方式發送不同的UI,然後讓AJAX(jQuery)更新DIV因此。一個DIV,多個UI,AJAX和PHP
作爲一個新手,在JavaScript/AJAX部分,我並不真正知道如何檢查用戶目前正在使用哪個用戶界面,我需要知道哪些用戶可以使用正確的參數調用PHP腳本。
下面是一些僞代碼:
<?php
print "<div id='target'>";
if($authenticated) {
//Check status of user in DB
if($subscribed) {
print "<input type='button' id='mybutton' value='Unsusbcribe'/>";
else {
print "<input type='button' id='mybutton' value='Susbcribe'/>";
}
} else {
print "Username <input type='button' id='username' value=''/>";
print "Password <input type='password' id='password' value=''/>";
print "<input type='button' id='mybutton' value='Logon'/>";
}
print "</div>";
?>
<script type="text/javascript" src="<?php echo $JQUERY['jquery.js']; ?>"></script>
<script type='text/javascript'>
//All buttons point to this event
$(function() {
$(':button').click(function() {
//How were we called?
switch($(#mybutton))
{
//Remote server sends new UI, and AJAX updates DIV locally
case 'Subscribe':
$(#target).html = ajax.post("index.php?action=subscribe");
case 'Unsuscribe':
$(#target).html = ajax.post("index.php?action=unsubscribe");
case 'Logon':
$(#target).html = ajax.post(username : $username, password: $password; "index.php?action=logon");
}
});
});
</script>
謝謝你的任何暗示。
編輯:對於那些想用同樣的方法來發布數據:
var username = $("#username").val();
$("#target").load("myscript.php", {username : username});
謝謝Derrick的提示。 – Gulbahar 2010-07-30 16:17:03