文本框失去鼠标焦点执行ajax+php

  • Post author:
  • Post category:php


o2o/admin/ category



view

<td class="text-c listorder"><input type="text" name="listorder" value="{$vo.listorder}" attr-id="{$vo.id}" size="3"></td>



view -> js

<script>
	var SCOPE = {
		'listorder_url': "{:url('category/listorder')}" ,
	}
</script>



public/admin/conmon/common.js

/*更新排序ajax*/
$('.listorder input').blur(function () {
    //编写抛送逻辑
    //获取主键id
    var id = $(this).attr('attr-id');
    //获取排序的值
    var listorder = $(this).val();
    //获取的值组合成抛送的数组
    var postDate = {
        'id' : id,
        'listorder' : listorder,
    };
    //获取url
    var url = SCOPE.listorder_url;
    //抛送http
    $.post(url,postDate,function (res) {
        if (res.code == 1){
            setTimeout(function () {
                location.href=res.data;
            },500)
        }
        else{
            layer.alert(res.msg,{icon:2});
        }
    },"json");
});



controller

public function listorder($id,$listorder)
    {
        $res = $this->obj->save(['listorder'=>$listorder],['id'=>$id]);
        if ($res){
            $this->result($_SERVER['HTTP_REFERER'],1,'success');
        }
        else{
            $this->result($_SERVER['HTTP_REFERER'],0,'更新失败');
        }
    }



版权声明:本文为s1095622320原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。