duanlu2935 2017-07-10 19:28
浏览 40

如何在旧CI中使用javascript成功函数传递值

i'm working with an old codeigniter. i'm calling a onchange function. i want to get data from controller and show it to a input filed which is an array.

view page code:

    <select name='feed_id[]' style='width:95px;'onchange="getfeedstock(0,this.value)"><?=$this->mod_feed->get_feeds()?></select>

<span><input type='text' name='stock[]' readonly value='' class='num_txt stock<?=$inc?>' /></span>

javascript:

<script >

    function getfeedstock(i,obj){
        //alert(obj);
        $.ajax({
            url:base_url+'feed_sale/get_feed_stock',
            type:'post',
            data:{
                feed_id:feed_id

            },
            success:function(data){
                //alert(data);
                //var stock=5;
                 //$('.stock').val(stock);
            },
            error:function(error,msg){
                alert(error+msg);
            }
        });
    }
</script>
  • 写回答

1条回答 默认 最新

  • dongtu0363 2017-07-11 06:14
    关注

    Use Output class of Codeigniter https://www.codeigniter.com/userguide2/libraries/output.html

    it will set page header to JSON type. And pass array using json_encode();

    all array of PHP will get in JSON object format in success callback of Ajax

    success: function(data) {
        alert(data.msg); // showing [Object][object] 
        //all array visible in console log Ctrl+Shift+I (in chrome)
        console.log(data);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序