ajax_post运用

前端之家收集整理的这篇文章主要介绍了ajax_post运用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

实现业务逻辑:

输入关联订单后,当鼠标在输入框中失去焦点,则触发js,通过ajax_post去返回关联订单交易号。

form表单中:

array(
            "title" => "关联订单","id"  => "relation_code","name"  => "relation_code",),array(
            "title" => "关联单交易号","id" => "relation_deal_code","name" => "relation_deal_code",@H_502_13@ 

tpl模板文件中:

//根据关联订单号获取关联交易号
    $("#relation_code").blur(function(){
        var relation_code = $("#relation_code").val();
        ajax_post({
            url:"?app_act=crm/tel_information/get_relation_deal_code",data:{relation_code:relation_code},callback:function(data){
                if(data.data.relation_code==''){
                    alert("该关联订单不存在!");
                    return;
                }
                $("#relation_deal_code").val(data.data.relation_deal_code);
            }
        });
    });@H_502_13@ 

M层:

//根据关联订单号获取关联交易号
    function get_relation_deal_code(array & $request,array & $response,array & $app) {
        $relation_code='';
        if(isset($request['relation_code']) && !empty($request['relation_code'])){
            $relation_code = $request['relation_code'];
        }
        $result = $this->mdl->get_relation_deal_code($relation_code);
        if($result){
            $relation_deal_code=$result['relation_code'];
            $relation_code=$result['record_code'];
        }else{
            $relation_deal_code='';
            $relation_code='';
        } 
        $response = return_value(1,"",array("relation_deal_code" => $relation_deal_code,"relation_code" => $relation_code));
    }

//根据关联订单号获取关联交易号
    function get_relation_deal_code($record_code)
    {
        $db = $GLOBALS['context']->db;
        $sql = "select record_code,relation_code from crm_consume where record_code = :record_code";
        return $db->get_row($sql,array(":record_code" => $record_code));
    }@H_502_13@

猜你在找的Ajax相关文章