Home > Backend Development > PHP Tutorial > PHP ajax 操作之后不要刷新页面更换图片

PHP ajax 操作之后不要刷新页面更换图片

WBOY
Release: 2016-06-23 14:27:40
Original
1014 people have browsed it

ajax php javascript function

   
        ');">
          PHP ajax 操作之后不要刷新页面更换图片 
        

                   }
        else{
        ?>
        ');">
          PHP ajax 操作之后不要刷新页面更换图片 
        

            
        



function xingxing(id,name){
       $.ajax({
          type: "POST",
          url: "",
          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代码来看 只需要改变ajax的返回值,不再是200 100这样的代码,而是需要更换的新的图片地址

然后用jquery定位到要改变的img标签将其src属性直接替换为新的图片地址即可.

从你的ajax代码来看 只需要改变ajax的返回值,不再是200 100这样的代码,而是需要更换的新的图片地址

然后用jquery定位到要改变的img标签将其src属性直接替换为新的图片地址即可.
------------------------------------------------------------------------------

代码贴出吧 大虾


项目 时间 大梨家报价 老张家报价 差价
禁断岛徒步+天然池浮潜+南部游 一日 50美元
南部观光 半日 25美元-30美元 25美金(珊瑚海滩,禁断岛、坦克海滩、圣梅卡尔大教堂) -5

function xingxing(id,name){
       $.ajax({
          type: "POST",
          url: "",
          processData: "false",
          data: "n=" + Math.random() + "&fn=" + escape(id) + "&starflag=" + escape(name) + "",
          success: function(msg){
            var msg = $.trim(msg);
             $("img").attr("src",msg);
            }
        }
   });
}

function xingxing(id,name){
       $.ajax({
          type: "POST",
          url: "",
          processData: "false",
          data: "n=" + Math.random() + "&fn=" + escape(id) + "&starflag=" + escape(name) + "",
          success: function(msg){
            var msg = $.trim(msg);
             $("img").attr("src",msg);
            }
        }
   });
}

图片改不了呀

@xuzuning 
版主 去那里了,出来  出来 

 
        ');">
          PHP ajax 操作之后不要刷新页面更换图片 
        

                   }
        else{
        ?>
        ');">
          PHP ajax 操作之后不要刷新页面更换图片 
        

            
        



function xingxing(id,name){
       $.ajax({
          type: "POST",
          url: "",
          processData: "false",
          data: "n=" + Math.random() + "&fn=" + escape(id) + "&starflag=" + escape(name) + "",
          success: function(msg){
            if(msg =='1'){
              $("#img_b").attr("src", "/themes/default/images/star01.gif"); 
            }else{
              $("#img_a").attr("src", "/themes/default/images/star02.gif"); 
            }
             
        }
   });
}

可恶 就是不变图片

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template