我目前有一个php文件执行:
<a href="test.php?foo=boo">test</a>
Run Code Online (Sandbox Code Playgroud)
我宁愿不必加载新页面并在onClick上执行.
有谁知道一个简单的方法来做到这一点?
我添加了一个更完整的示例,包括建议的ajax.我仍然无法让它工作.
<script type="text/javascript">
$('li').click(function() {
$.ajax({ type: "GET", url: "test.php", data: { foo: 'boo' }, success: function(data){
// use this if you want to process the returned data
alert('complete, returned:' + data);
}});
});
</script>
</head>
<body>
<div id="header">
<h1>Title</h1>
</div>
<ul>
<li><a href="#">Test</a></li>
</ul>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)