将span标签id发送到URL,而不刷新页面
Send span tag id to the URL without refresh page
<span id="50">Hello</span>
发送50到URL不刷新页面通过点击上面的span
$("span").click(function(){
$(this).load("http://www.example.com/abc.php?q="+$(this).attr('id'), function(r,s,x){...});
});
$("span").click(function(){
$.post("demo_.php",{
Id:$(this).attr('id');
},
function(data,status){
alert("Data: " + data + "'nStatus: " + status);
});
});
响应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>
相关文章:
- 刷新后重定向到其他URL
- window.location未刷新到现有URL
- 在浏览器中更改页面的URL,无需刷新和HTML5模式
- Angular/UI路由器-如何在不刷新所有内容的情况下更新URL
- Angular,ui路由器;绑定”;到url,也不刷新
- 如何在不刷新页面的情况下更改URL
- dojo-dgrid带有store from url(json数据)重载/刷新按钮
- 更新f5上的URL或刷新按钮
- 在url中传递参数时,如何使用AJAX阻止页面刷新
- PHP-如何让别人可以'不要更改url中的参数,也不要在刷新页面时再次运行脚本
- 用javascript附加主url,刷新页面无效
- 如果可能的话,刷新后保留iframe url
- 剑道自动完成刷新url
- 对于特定的URL,每5秒刷新一次表
- 用javascript交换url后刷新类似facebook的按钮不起作用
- 使用jQuery修改url参数而不刷新页面
- 单击具有实际 URL 的链接时刷新
- 当我在 Emberjs 中使用 {{link-to}} 中的 id 刷新 url 时,子出口变为空
- 为什么当我在 Emberjs 中最后用“id”刷新 url 时,我得到一个空白应用程序
- 刷新 URL 时,打开卸载确认警报两次