【问题标题】:retrieve data from controller in json code igniter从 json 代码点火器中的控制器检索数据
【发布时间】:2013-01-25 12:18:33
【问题描述】:

    $(document).ready(function(){

        $('#bill_no').blur(function(){

            if( $('#bill_no').val().length >= 3 )
                {
                  var bill_no = $('#bill_no').val();
                  getResult(bill_no); 
                }
            return false;
        })
        function getResult(billno){
            var baseurl = $('.hiddenUrl').val();
          //  $('.checkUser').addClass('preloader');
            $.ajax({
                url : baseurl + 'returnFromCustomer_Controller/checkBillNo/' +   billno,
                cache : false,
                dataType: 'json',
                success : function(response){
                    $(".text").prepend(response.text);
                }
            })
        }
    })

我的控制器

         function checkBillNo($billno){
    $this->load->model('returnModel');
    $query = $this->returnModel->checkBillNo($billno);



        header('Content-Type: application/x-json; charset=utf-8');
       echo(json_encode($this->returnModel->sale($billno)));


}

从控制器获取值后,如何在跨度类“文本”中打印值.. 我已经签入了 firebug,在其中的响应选项卡中我成功获得了结果,但是如何在跨度的视图页面中打印类..

【问题讨论】:

  • 请显示您的 json 响应。
  • 这是响应 {"result":"142"}

标签: php javascript json codeigniter jquery


【解决方案1】:

您需要像这样以objet.parameter 获得响应:

success : function(response)
 {
    $(".text").html(response.result);
 }

因为正如你在评论中所说:

这是响应 {"result":"142"}

【讨论】:

  • 是的,它现在可以工作了...如果您不介意,我可以再问您一个问题吗?
  • @mynameisjohn - 是的,当然.. 随便问什么
【解决方案2】:
 success : function(response)
 {
    $(".text").html(response);
 }

【讨论】:

  • 我在我的 html 页面中得到了这个...[object Object]
  • @mynameisjohn 尝试用 .text 代替 .html
【解决方案3】:

你可以使用segment no从url中检索参数

function checkBillNo($billno)
{
    $this->load->model('returnModel');

    $query = $this->returnModel->checkBillNo($billno);

    $billno =   $this->uri->segment(3);
    $billno_results  = $this->returnModel->sale($billno)

    //header('Content-Type: application/x-json; charset=utf-8');
    echo    json_encode($billno_results);
}

这里的 $query 有什么用。你也不需要设置标题类型

你的 ajax 在这里

$.ajax({
    url : baseurl + 'returnFromCustomer_Controller/checkBillNo/' +   billno,
    cache : false,
    dataType: 'json',
    success : function(response){
        $(".text").prepend(response);
    }
})

看你不需要 response.text 简单的打印响应

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-27
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    • 2018-08-15
    • 2019-03-22
    • 2014-01-05
    • 1970-01-01
    相关资源
    最近更新 更多