• 前端代码
<script language="javascript" type="text/javascript" src="<?php echo base_url();?>/js/jquery-1.7.2.min.js"></script>
<script>
function add_ip(bip,eip,area_id) {
        var action = "<?php echo site_url('test/add_test'); ?>";
        var yn = window.confirm("测试");
        if (!yn) {
                return;
        }
        $.ajax({
                type:"post",
                dataType:"json",
                url:action + "?rr=" + Math.random(),
                data:{
                "bip": bip,
                "eip": eip,
                "area": area_id
                },
                success:function(retObj) {
                        if (retObj.code == 0) {
                                alert("设置成功");
                        } else {
                                alert("设置失败:"+retObj.msg);
                        }
                },
                fail:function(retObj) {
                        alert("发送请求失败code="+retObj.code);
                }
        });
}

</script>

后端代码:

function add_test() {
                $bip = $this->input->post('bip', true);
                $eip = $this->input->post('eip', true);
                $area_id = intval($this->input->post('area_id',true));
                if ($this->test_mdl->add($bip, $eip, $area_id)) {
                //      echo "add OK";  
                } else {
                //      echo "add fail";
                }       
                echo '{"code":0, "msg":""}';
        } 

注意:上面注释了两行代码,注意,如果输出多其他信息,又不是以json的格式返回,就会导致前端不能正常接受回调的内容。

 程序猿必读

相关文章:

  • 2022-01-23
  • 2021-12-04
  • 2021-05-17
  • 2021-12-14
  • 2021-11-20
  • 2022-02-24
猜你喜欢
  • 2021-11-19
  • 2022-12-23
  • 2021-08-26
  • 2022-01-27
  • 2021-11-23
  • 2022-01-31
相关资源
相似解决方案