weixin_33701564 2017-05-16 08:26 采纳率: 0%
浏览 32

Ajax调用以显示数据

I am very new in web developing. In my database, I have the table named customers. There are two columns named customer name, and customer address. in my interface I have a field where I can search for the customers. in interface, there is another field named "customer address". My aim is to fill the field customer address no sooner had the customer name is selected.

This is my view file

<tr>
    <th valign="top" style="text-align:right">Customer Name:&nbsp;&nbsp;</th>
    <td><input type='text' id="customer_name" class="text_box" autocomplete="off" name='customer_name' value="<?= set_value('customer_name', $customer_name) ?>" /><?= form_error('customer_name', '<span class="error">', '</span>') ?>
        <div class="jcustomer_list"></div>
        <input name="customer_id" value="" type="hidden" class="customer_id">
    </td>
</tr>

<tr>
    <th valign="top" style="text-align:right">Customer Address:&nbsp;&nbsp;</th>
    <td><input type='text' id="customer_adress" class="text_box" autocomplete="off" name='customer_adress' value="<?= $_REQUEST['customer_adress']  ?>" /><?= form_error('customer_adress', '<span class="error">', '</span>') ?>
        <div class="jcustomer_list"></div>
        <input name="customer_id" value="" type="hidden" class="customer_id">
    </td>
</tr>

This is my AJAX class

bind:function(){

    $j('.jcustomer_list').find('li').unbind('click');
    $j('.jcustomer_list').find('li').bind('click',function(){

        $j('#customer_name').val($j(this).attr('title'));
        //$j('#customer_address').val($j(this).attr('title'));

        $j('.customer_id').val($j(this).attr('rel'));
        var cid=$j(this).attr('rel');
        customer.getPreviousBalance(cid);   
        customer.getCustmerAddress(cid);
        $j('.jcustomer_list').css('display','none');
    });
},

getCustmerAddress:function(cid){
    $j.ajax({
        type:'post',
        url:base_url+'ajax/load_customer_address',
        data:{
            cid:cid
        },
        //here a success function must be added but I am not being able to this.

        error:function(a,b,c){
        },
    });
    }
}

This is my common helper function

public static function get_customer_address($cid) {
    $CI = &get_instance();
    $c = sql::row("customers", "customer_id='$cid'", "customer_address");
    return $c;      
}
  • 写回答

1条回答 默认 最新

  • weixin_33674976 2017-09-01 04:09
    关注

    Your script looks like you have added extra } bracket & here is the AJAX Code should be. I am assuming your controller function return the correct result.

    $j.ajax({
        type:'post',
        url:base_url+'ajax/load_customer_address',
        data:{
            cid:cid
        },
        dataType: "json",
        success: function (response) {              
             console.log(response);
            // Your data came here   
        },
        error:function(a,b,c){
        },
    });
    
    评论

报告相同问题?