您可能需要一些 AJAX 来执行异步获取请求以从 /users/delete 和 /users/new 从 index.php 检索数据
您也可以使用 JQuery 插件 (http://jquery.com/) 来简化 AJAX 调用
这是一个使用 JQuery $.get() 的 javascript 示例,它发出异步获取请求
<html>
<head>
...import jquery javascript plugin...
<script>
//executes init() function on page load
$(init);
function init(){
//binds click event handlers on buttons where id = new and delete
// click function exectutes createUser or deleteUser depending on the
button that has been clicked
$('#new').click(function(){createUser();});
$('#delete').click(function(){deleteUser();});
}
function createUser(){
//submits a get request to users/new and alerts the data returned
$.get('users/new',function(data){alert('user is created : '+data)});
}
function deleteUser(){
//submits a get request to users/delete and alerts the data returned
$.get('users/delete',function(data){alert('user is deleted : '+data)});
}
</script>
</head>
<body>
<input id='new' type='button' />
<input id='delete' type='button' />
</body>
</html>