≡
  • 网络编程
  • 数据库
  • CMS技巧
  • 软件编程
  • PHP笔记
  • JavaScript
  • MySQL
位置:首页 > 网络编程 > AJAX

Ajax异步无刷新修改数据 - 传值的简单示例

人气:802 时间:2018-09-26

这篇文章主要为大家详细介绍了Ajax异步无刷新修改数据 - 传值的简单示例,具有一定的参考价值,可以用来参考一下。

感兴趣的小伙伴,下面一起跟随四海网的小编罗X来看看吧。
JS代码如下:

/**
 * 异步无刷新传值
 *
 * @param 
 * @arrange (512.笔记) www.q1010.com
 **/
//修改商品
//把返回值放入表单中做默认值
function do_editgoods(id){
    $('#editgoods').modal('open');
    $.get('/Home/Price/edit/item_id/'+id,function(result){
       document.getElementById("hid").value = result.content['id'];
       document.getElementById("item_id").value = result.content['item_id'];
       document.getElementById("outer_item_id").value = result.content['outer_item_id'];
       document.getElementById("goods_name").value = result.content['goods_name'];
       document.getElementById("standard").value = result.content['standard'];
       document.getElementById("low_price").value = result.content['low_price'];
       document.getElementById("minus_price").value = result.content['minus_price'];
       document.getElementById("moni_url").value = result.content['moni_url'];
    },'json');
    return false;
}

//将表单的默认值通过异步传到控制器
function do_edit(){
    $.post(
        '/Home/Price/to_edit',
        {   'hid':$(".edit_hid").val(),
            'item_id':$(".edit_item_id").val(),
            'outer_item_id':$(".edit_outer_item_id").val(),
            'goods_name':$(".edit_goods_name").val(),
            'standard':$(".edit_standard").val(),
            'low_price':$(".edit_low_price").val(),
            'minus_price':$(".edit_minus_price").val(),
            'moni_url':$(".edit_moni_url").val()
        },function(result){
            if(result.code == 200){
                //$("#msg1").cl
                $("#msg2").addClass('am-text-success');
                $("#msg2").html('修改成功!');
                $("#msg2").html(result.msg);
                //window.location.href="/Home/Index/index.html";
            }else{
                //$("#msg1").addClass('am-text-danger');
                $("#msg2").html(result.msg);
            }    },'json');
}

//控制器进行处理
/**
* 修改商品价格*/
    public function edit(){
    $map['item_id'] = $_GET['item_id'];                 //获取页面传过来的商品编号
    $to_display = M('haoyao_price_compare') -> where($map) -> find();     //查处所需要的信息//成功后返回客户端新增的用户ID,并返回提示信息和操作状态
    $this->ajaxReturn(array('code'=>200,'content'=>$to_display));//将获取到的数据返回到页面
    }

    public function to_edit(){
    $map['id'] = $_POST['hid'];
//获取页面传过来的商品编号
    $data['item_id'] = $_POST['item_id'];
//获取页面传过来的商品编号
    $data['outer_item_id'] = $_POST['outer_item_id'];
//获取页面传过来的外部商家编号 
$data['goods_name'] = $_POST['goods_name'];
//获取页面传过来的商品名称 
$data['standard'] = $_POST['standard'];
//获取页面传过来的商品规格
$data['low_price'] = $_POST['low_price'];
//获取页面传过来的商品最低价格
$data['modi_time'] = date('Y-m-d H:i:s',time());
//获取页面传过来的商品修改时间
$data['minus_price'] = $_POST['minus_price'];
//获取页面传过来的商品优惠价格
$data['mino_url'] = $_POST['moni_url'];
//获取页面传过来的商品链接 
$res = M('haoyao_price_compare')->where($map)->save($data);if($res){$this->ajaxReturn(array('code'=>200));
}
}

// 来自:四海网(www.q1010.com)

本文来自:http://www.q1010.com/178/1683-0.html

注:关于Ajax异步无刷新修改数据 - 传值的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。

关键词:无刷新

您可能感兴趣的文章

上一篇:Ajax修改页面数据信息的实现方式
下一篇:ajax回调函数刷新页面的简单示例
热门文章
  • 完美解决ajax跨域请求下parsererror的错误
  • 用ajax传递json到前台中文出现问号乱码问题的解决办法
  • AJAX 实现页面内跳转的简单例子
  • AJAX 实现页面跳转简单示例
  • Ajax打开新窗口被浏览器拦截的两种解决办法
  • Ajax修改页面数据信息的实现方式
  • Ajax异步无刷新修改数据 - 传值的简单示例
  • AJAX实例:用callback函数的AJAX实例
  • AJAX实例:用AJAX从数据库返回数据
  • AJAX实例:用AJAX从ASP 文件返回数据
  • 最新文章
    • 用ajax传递json到前台中文出现问号乱码问题的解决办法
    • AJAX用于判定用户是否注册
    • ajax实现异步文件或图片上传功能
    • Ajax打开新窗口被浏览器拦截的两种解决办法
    • Ajax验证用户名或昵称是否已被注册
    • Ajax动态为下拉列表添加数据的实现方法
    • Ajax的特性及乱码问题
    • ajax提交手机号去数据库验证并返回状态值
    • 完美解决ajax跨域请求下parsererror的错误
    • 基于Ajax技术实现无刷新用户登录功能

四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。