Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery jqgrid不会从远程URL加载json数据_Jquery_Jqgrid - Fatal编程技术网

Jquery jqgrid不会从远程URL加载json数据

Jquery jqgrid不会从远程URL加载json数据,jquery,jqgrid,Jquery,Jqgrid,我在JSFIDLE中设置了一个jqgrid: $("#list").jqGrid({ height: 700, width: 900, datatype: 'json', mtype:'GET', url: url, colNames:['Col 1','Col 2'], colModel :[

我在JSFIDLE中设置了一个jqgrid:

$("#list").jqGrid({
            height: 700,  
            width: 900,  
            datatype: 'json', 
            mtype:'GET',
            url: url,
            colNames:['Col 1','Col 2'],
            colModel :[ 
              {name:'col1', index:'col1'},
              {name:'col2', index:'col2'},
            ],
            pager: '#pager_list',
            rowNum:20,
            rowList:[20,50,100],
            viewrecords: true,
            caption: 'Test',
            gridview : true,    
           });

但是,它不会从远程URL加载json数据。当加载到浏览器中时,json看起来很好


但是,当我在localhost上托管jqgrid和json脚本时,它确实可以工作。以前有人经历过类似的事情吗?非常感谢您的帮助:)

您需要在服务器上启用CORS。 将其放在返回JSON的页面上

<?php
header("Access-Control-Allow-Origin: *");

不过,这可能行不通,因为您仍然可能会遇到某种CORS错误

请尝试使用Jsonp进行交叉请求

使用


分配列模型名,使用json键val进行索引。

请求的资源上不存在“Access Control Allow Origin”标题。这意味着您需要在您的服务器上正确设置CORS将数据类型更改为JSONP成功了,非常感谢!没有数据
$("#list").jqGrid({
            height: 700,  
            width: 900,  
            datatype: 'json', 
            ajaxGridOptions: { jsonp: true, contentType: 'application/json; charset=utf-8' }, 
            mtype:'GET',
            // rest of your code
    $("#list").jqGrid({
                height: 700,  
                width: 900,  
                datatype: 'json', 
                mtype:'GET',
                url: "http://202.137.146.116/tokoweblink/weblink.php?q=1&agent=ABVT0010",
                ajaxGridOptions: { jsonp: true, contentType: 'application/json; charset=utf-8' },
                colNames:['Inv No', 'Client', 'Amount'],
                colModel:[
                        {name:'id',index:'id', width:55},
                        {name:'name',index:'name asc, invdate', width:100},
                        {name:'amount',index:'amount', width:80, align:"right"}
                        ],
                 });