如何在php

时间:2016-10-27 14:41:45

标签: php json ajax

我需要在php中接收ajax响应数据作为数组。我在视图页面中的jquery代码和ajax响应数据来自CI函数json_encode($data)。我进入alert(data)。但是如何在我的视图页面(同一页面)中将此json data作为数组,我可以使用php提取数组。我google了很多但没有找到这种类型的解决方案。什么是在php页面中将ajax成功数据作为变量的实际方法。

function client_deatails(){
  $data=$this->BillingModel->client_details_param($client_id, $company_id, $from, $to);
  echo json_encode($data);
}

查看页面:

<?php
 if(!empty($data)){
   print_r($data);
 }
?>

jQuery的AJAX

        $(document).ready(function () {
            $("#client_id").focus();
            $(".param").change(function () {
                var dataString = {
                    client_id: $('#client_id').val(),
                    from: $('#fromDate').val(),
                    to: $('#toDate').val()
                };
                var jsonString = JSON.stringify(dataString);

                $.ajax({
                    url: "<?php echo base_url(); ?>billing/client_deatails",
                    data: {data: jsonString},
                    type: "POST",
                    dataType: 'json',
                    success: function (data) {
                        //$('#param-data').html(data);

                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("some error");
                    }
                });
            });
        });

0 个答案:

没有答案