AJAX PHP 循环之后点击状态更换图片
<?php
foreach ( $account as $key => $value)
{
?>
<!-- 图片的状态 1 显示 2 隐藏 -->
<?php if($value['starflag'] == 1){ ?>
<a href="javascript:void(0);" onclick="xingxing('<?php echo $value['id']."','".$value['name']; ?>');">
<img src="/themes/default/images/star02.gif" im="images/star02.gif" />
</a>
<?php
}
else{
?>
<a href="javascript:void(0);" onclick="xingxing('<?php echo $value['id']."','".$value['name']; ?>');">
<img src="/themes/default/images/star01.gif" im="images/star01.gif" />
</a>
<?php } ?>
</a>
<?php } ?>
function xingxing(id,name){
$.ajax({
type: "POST",
url: "<?php echo base_url('test/fangfa'); ?>",
processData: "false",
data: "n=" + Math.random() + "&fn=" + escape(id) + "&starflag=" + escape(name) + "",
success: function(msg){
var msg = $.trim(msg);
switch (msg){
case "200":
location.replace(location.href);
case "110": //重新登录
location.replace(location.href);
case "120": //修改密码
location.replace(location.href);
break;
default:
alert("失败");
location.replace(location.href);
break;
}
}
});
}
------------------------------------------------------------------------------
我的问题是 调用AJAX 之后直接更换图片不需要在从新刷新一次页面,求大虾帮忙,在线等 ajax php javascript
[解决办法]
不知道你要做什么?
既然是用了 jquery,那么就该用 jquery 的传统写法
php 部分
<span class="img">
<img src="/themes/default/images/star02.gif" style="display:<?php echo $value['starflag'] == 1? '' : 'none' ?>" name="<?php echo $value['name']?>" id="<?php echo $value['id']?>" />
<img src="/themes/default/images/star01.gif" style="display:<?php echo $value['starflag'] == 1? 'none' : '' ?>" name="<?php echo $value['name']?>" id="<?php echo $value['id']?>" />
</span>
$(function() {用 $.ajax 也是一样
$(".img").click(function() {
$(this).children().toggle();
$.post("<?php echo base_url('test/fangfa'); ?>",
{
n : Math.random(),
fn : escape($(this).attr('id')),
starflag : escape($(this).attr('name'))
},
function(msg){
//你需要的其他处理
});
});
});