<span id="50">Hello</span>
点击上面的
,将50发送到没有刷新页面的网址答案 0 :(得分:0)
$("span").click(function(){
$(this).load("http://www.example.com/abc.php?q="+$(this).attr('id'), function(r,s,x){...});
});
答案 1 :(得分:0)
$("span").click(function(){
$.post("demo_.php",{
Id:$(this).attr('id');
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
答案 2 :(得分:0)
响应ajax调用的abc.php的内容
<?php
//perform your work here with span id
if(isset($_GET['value'])){
$id = $_GET['value']; //contains the span id sent using ajax
$output['id']=$id; // I'm just going to echo the id
header('Content-type: application/json');
echo json_encode($output);
}
?>
完成ajax调用的test.php的内容
<span id="50">Hello</span>
<script src="js/jquery-1.10.2.min.js"></script>
<script>
jQuery(document).ready(function($) {
$('span').click(function(e) {
var value = $(this).attr('id');
$.ajax({
url: 'abc.php',
type: 'get',
data: {value:value},
dataType: 'json',
success: function(rows){
console.log('ajaX');
alert("from abc.php: value = " + rows['id']);
}
});
});
});
</script>