【问题标题】:ExtJS: missing } after property list but I dont see any code errorsExtJS:属性列表后缺少 } 但我没有看到任何代码错误
【发布时间】:2011-03-15 11:23:44
【问题描述】:

加载失败 -- 参数:[Object api=Object, Object request=Object reader=Object scope=Object, Object tId=0 status=200 statusText=OK, SyntaxError: missing } after property list message=missing } after property列表]

我通过向我的商店添加异常得到了该错误,但在我的代码中没有看到任何真正的错误...也许另一双眼睛会有所帮助。

php:

 case 'messages':
                    if(isset($_SESSION['id'])){
            $stmt = $dbh->prepare("Select ID, ReceivedAt, Message from SystemEvents Limit 100");
                            $stmt->execute();

            while($tmp = $stmt->fetch()){
                $y .= '{"ID":"'.$tmp['ID'].'","ReceivedAt":"'.$tmp['ReceivedAt'].'","Message":"'.$tmp['Message'].'"},';
            }
            $y = trim($y,',');
            if(isset($_REQUEST['callback'])){
                echo $_REQUEST['callback'].'({"dates":['.$y.']});';
            }else{
                echo '{"dates":['.$y.']}';
            }
        }else{
            if(isset($_REQUEST['callback'])){
                                    echo $_REQUEST['callback'].'({success: false, data{"error_title": "Error", "errormsg": "Cannot display dates"}})';
                            }
                            else{
                                    echo '{success: false, data{"error_title": "Error", "errormsg": "Cannot display dates"}}';
                            }
                    }
            break;

extjs:

Ext.onReady(function(){

var logStore = new Ext.data.JsonStore({
    autoLoad: true,
    url: 'inc/interface/config.php?list=messages',
    root: 'dates',
    idProperty: 'ID',
    fields: ['ID', 'ReceivedAt', 'Message'],
    listeners: {
                loadexception: function() {
                    console.log('load failed -- arguments: %o', arguments);
                }
        }
}); 

var dateStore = new Ext.data.JsonStore({
    autoLoad: true,
    url: 'inc/interface/config.php?list=date_options',
    root: 'dates',
    idProperty: 'ID',
    fields: ['ID', 'ReceivedAt'],
    listeners: {
                loadexception: function() {
                    console.log('load failed -- arguments: %o', arguments);
                }
        }
});

var dateSelect = new Ext.form.DateField({
    fieldLabel: 'Pick a date',
    width: 190,
    align: 'center',
    frame: true
});

var dateCombo = new Ext.form.ComboBox({
    store: dateStore,
    mode: 'local',
    valueField: 'ID',
    displayField: 'ReceivedAt',
    editable: false,
    emptyText: 'Select a Date',
    width: 250,
    listeners:{
        activate: function(){
            dateStore.reload();
        }
    }
});

var searchField = new Ext.form.TextField({
    fieldLabel: 'Search Criteria',
    emptyText: 'Search....',
    width: 190, 
    frame: true

});

var searchButton = new Ext.Button({
    text: 'Search',
});

var clearButton = new Ext.Button({
    text: 'Clear',
    tooltip: 'Clears all your search data'
});

var searchPanel = new Ext.Panel({
    layout: 'form',
    region: 'east',
    width: 300,
    collapsible: true,
    alignButton: 'right',
    title: "Search Panel",
    items: [dateSelect, dateCombo, searchField],
    buttons: [clearButton, searchButton]
});


var logGrid = new Ext.grid.GridPanel({
    region: 'center',
    store: logStore,
    colModel: new Ext.grid.ColumnModel({
        columns: [{
            id: 'received',
            header: 'Received',
            dataIndex: 'ReceivedAt',
            width: 250
        },{
            id: 'message',
            header: 'Logs',
            dataIndex: 'Message',
            width: 750
        }]
    }),
});


var mainViewport = new Ext.Viewport({
    layout: 'border',
    items: [logGrid, searchPanel]
});

});

我认为发布我的 php 的其余部分无关紧要,因为一切正常,但希望有人能发现我的坏眼睛无法发现的东西。

【问题讨论】:

    标签: php json extjs store


    【解决方案1】:

    我在这里看到了一个额外的逗号:

    var searchButton = new Ext.Button({
        text: 'Search',
    });
    

    也在 LogGrid 上。可能就是这样

    编辑:如果有错误data{"error_title" 错误,则从 PHP 发回的响应看起来不是有效的 JSON,应该是 data:{"error_titel"

    你真的应该看看在 PHP 中构建对象/数组,并使用 json_encode 来回显这些对象/数组,而不是手动构建 JSON。

    【讨论】:

    • 奇怪的是我可以在PHP中取出:“Message”:“'.$tmp['Message'].'”,并且网格将显示日期就好了。我得看看那个 json_encode。
    • 好吧,Message 可能包含引号或其他 JSON/JavaScript 字符串文字中的特殊字符。未能为其上下文转义字符是安全漏洞的一大来源,这就是为什么您要使用 json_encode 来创建输出而不是字符串吊索。
    • 下面的任何东西都会被视为特殊字符吗?这只是您的基本 dhcp 日志。我已经将问题归结为此处无法正确解析的内容,因为我的代码可以正常工作并且可以将其他所有内容存储在其应有的位置……除了此“消息”部分。 4 月 9 日 00:00:02 dh1 dhcpd:DHCPACK 在 10.193.XX 到 00:21:xx:53:xx:e1 (xxxxxx-PC) 通过 10.193.xx.xx 4 月 9 日 00:00:02 dh1 dhcpd:添加新从 xx.wifi-uhs.xx 到 10.193.xx.xx Apr 9 00:00:02 dh1 dhcpd 的正向映射:添加了从 242.244.xx.xx.in-addr.arpa 的反向映射。到 xx.wifi-uhs.xx
    【解决方案2】:

    顺便说一句:要查找杂散逗号,我使用以下模式进行搜索:

    \,\s*(}|])

    这可以节省大量时间,特别是因为不同的浏览器比其他浏览器更健壮地处理错位的逗号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-23
      • 2017-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多