Php SyntaxError:JSON.parse:使用codeigniter调用ajax时出现意外字符

Php SyntaxError:JSON.parse:使用codeigniter调用ajax时出现意外字符,php,jquery,ajax,json,codeigniter,Php,Jquery,Ajax,Json,Codeigniter,我正在使用codeigniter。当我通过提供文件的完整路径来调用页面的ajax请求时,它可以正常工作: <!DOCTYPE html> <html lang="en"> <head> <title id='Description'>In this example is demonstrated how to implement server filtering, sorting and paging with jqxGrid.&l

我正在使用codeigniter。当我通过提供文件的完整路径来调用页面的ajax请求时,它可以正常工作:

    <!DOCTYPE html>
<html lang="en">
<head>
    <title id='Description'>In this example is demonstrated how to implement server filtering, sorting and paging with jqxGrid.</title>
    <link rel="stylesheet" href="http://localhost/jqwidgets-ver3.2.1/jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/scripts/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxmenu.js"></script>
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxgrid.selection.js"></script>   
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxgrid.filter.js"></script>  
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxgrid.sort.js"></script>        
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxdata.js"></script> 
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxlistbox.js"></script>  
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxgrid.pager.js"></script>       
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/jqwidgets/jqxdropdownlist.js"></script> 
    <script type="text/javascript" src="http://localhost/jqwidgets-ver3.2.1/scripts/demos.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
        // prepare the data
        var source =
        {
            datatype: "json",
            datafields: [
            { name: 'ShipName', type: 'string'},
            { name: 'ShipAddress', type: 'string' },
            { name: 'ShipCity', type: 'string' },
            { name: 'ShipCountry', type: 'string' }
        ],
        cache: false,
        url: 'http://localhost/CodeIgniter_2.1.4/index.php/blog/controllerfunction',
        filter: function()
        {
            // update the grid and send a request to the server.
            $("#jqxgrid").jqxGrid('updatebounddata', 'filter');
        },
        sort: function()
        {
            // update the grid and send a request to the server.
            $("#jqxgrid").jqxGrid('updatebounddata', 'sort');
        },
        root: 'Rows',
        beforeprocessing: function(data)
        {       
            if (data != null)
            {
                source.totalrecords = data[0].TotalRows;                    
            }
        }
        };      
        var dataadapter = new $.jqx.dataAdapter(source, {
            loadError: function(xhr, status, error)
            {
                alert(error);
            }
        }
        );

        // initialize jqxGrid
        $("#jqxgrid").jqxGrid(
        {       
            source: dataadapter,
            width: "100%",
            filterable: true,
            sortable: true,
            autoheight: true,
            pageable: true,
            virtualmode: true,
            rendergridrows: function(obj)
            {
                return obj.data;    
            },
            columns: [
                { text: 'Ship Name', datafield: 'ShipName'},
                { text: 'Address', datafield: 'ShipAddress'},
                { text: 'City', datafield: 'ShipCity'},
                { text: 'Country', datafield: 'ShipCountry'}
            ]
        });
    });
    </script>
</head>
<body class='default'>
    <h1>Shipment Records</h1>
    <div style="width: 1000px" id="jqxgrid"></div>
</body>
</html>
但是

显示错误:SyntaxError:JSON.parse:意外字符


我没有在代码中做任何其他更改

错误是说响应的内容中有错误,所以调试的唯一方法是查看响应中显示的内容。转到AJAX正在浏览器中加载的URL,并将其保存为文本文件,或使用“查看源代码”将其完全按原样显示。如果你看不出有什么问题,请编辑你的问题以包含JSON和完整的错误消息(我很惊讶它没有告诉你什么字符是意外的)。可能是你的输出在JSON之前有一些不需要的字符。您可以尝试在输出数据之前清除缓冲区。
url: 'http://localhost/CodeIgniter_2.1.4/application/view/serverfiltering_paging_and_sorting_data.php',
url: 'http://server/CodeIgniter_2.1.4/index.php/controllername/controlerfunction',