简体   繁体   English

自定义字符串 - 缺少:属性列表后

[英]Custom String - Missing : after property list

I have been working on getting $.ajax data compiled by using an php class I wrote. 我一直在努力通过使用我编写的php类来编译$ .ajax数据。 The data come out like this: 数据如下:

{ 
0: [ 
    { Status : "example status 2"
    , Contact ID Number : "1"
    , Date Entered : "2011-06-15"
    , Date Assigned : "2011-06-15"
    , Date Last Modified : "2011-06-15"
    , Deceased Date : ""
    , Linked To Registrant 1 : "Leona Brown"
    , Relationship 1 : "Father"
    , Authorization 1 : "1"
    , Linked To Registrant 2 : "Henry Sale"
    , Relationship 2 : "Husband"
    , Authorization 2 : "1"
    , Location : "Hamilton Harron Funeral Home"
    , Sales Manager : "Dan Thompson"
    , Counselor : "Mike Brown"
    , Registration Number : "1"
    , Registration Date : "2001-05-11"
    , Program 1 Number : "2"
    , Program 1 Date : "2003-11-05"
    , Program 1 Name : "Non Registrant Test Program - Advantage"
    , Program 2 Number : "--"
    , Program 2 Date : "--"
    , Program 2 Name : "--"
    , First Name : "Onelia"
    , Last Name : "Garcy"
    , Address Location 1 : "home"
    , Address 1 : ""
    , City 1 : "Houston"
    , State/Province 1 : "Texas"
    , Zip/Postal Code 1 : "77019"
    , Home Phone : "--"
    , Work Phone : "--"
    , Mobile Phone : "--"
    , Pager : "--"
    , Other Phone : "--"
    , Email : ""
    , Sales Type : "Pre-Need"
    , Note 1 : "This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. " 
    } 
]
, 1: [ 
    { Status : ""
    , Contact ID Number : "2"
    , Date Entered : "2011-07-02"
    , Date Assigned : "2011-07-02"
    , Date Last Modified : "2011-07-02"
    , Deceased Date : ""
    , Linked To Registrant 1 : "--"
    , Relationship 1 : "--"
    , Authorization 1 : "--"
    , Linked To Registrant 2 : "--"
    , Relationship 2 : "--"
    , Authorization 2 : "--"
    , Location : "Floral Haven Funeral Home "
    , Sales Manager : "Jayson Gordon"
    , Counselor : "Henry Murdoc"
    , Registration Number : "3"
    , Registration Date : "2003-12-02"
    , Program 1 Number : "4"
    , Program 1 Date : "2004-03-05"
    , Program 1 Name : "Non Registrant Test Program - Advantage"
    , Program 2 Number : "--"
    , Program 2 Date : "--"
    , Program 2 Name : "--"
    , First Name : "Leo"
    , Last Name : "Brown"
    , Address Location 1 : "home"
    , Address 1 : "5330 Ridge Rd "
    , City 1 : "Burlington"
    , State/Province 1 : "Ontario"
    , Zip/Postal Code 1 : "LVL7N9"
    , Home Phone : "9053919735"
    , Work Phone : "--"
    , Mobile Phone : "9057303737"
    , Pager : "--"
    , Other Phone : "--"
    , Email : "hmind@dont.com"
    , Sales Type : "PN to AN"
    , Note 1 : "This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. " 
    } 
]
, 2: [ 
    { Status : "example1 status"
    , Contact ID Number : "3"
    , Date Entered : "2011-09-05"
    , Date Assigned : "2011-09-05"
    , Date Last Modified : "2011-09-05"
    , Deceased Date : ""
    , Linked To Registrant 1 : "Onelia Gary"
    , Relationship 1 : "Wife"
    , Authorization 1 : "1"
    , Linked To Registrant 2 : "--"
    , Relationship 2 : "--"
    , Authorization 2 : "--"
    , Location : "First Memorial Funeral Services"
    , Sales Manager : "Dan Thompson", Counselor : "Steve Brown"
    , Registration Number : "5"
    , Registration Date : "2010-11-11"
    , Program 1 Number : "7"
    , Program 1 Date : "2011-08-19"
    , Program 1 Name : "Non Registrant Test Program - Dignity"
    , Program 2 Number : "6"
    , Program 2 Date : "2011-07-03"
    , Program 2 Name : "Non Registrant Test Program - Advantage"
    , First Name : "Henry"
    , Last Name : "Murdoc"
    , Address Location 1 : "company"
    , Address 1 : "9055 Harvy Rd. 4"
    , City 1 : "Burlington"
    , State/Province 1 : "Ontario"
    , Zip/Postal Code 1 : "L7L5Z7"
    , Home Phone : "9055679602"
    , Work Phone : "9057455209"
    , Mobile Phone : "--"
    , Pager : "--"
    , Other Phone : "--"
    , Email : "pewter@live.com"
    , Sales Type : "At-Need"
    , Note 1 : "This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. "
    } 
   ] 
}

Firebug reports this error: Firebug报告此错误:

missing : after property id .../view_contacts_search_1.php# Line 188 缺失:属性id ... / view_contacts_search_1.php #Line 188

It fails when instantiating a variable: 它在实例化变量时失败:

<script type='text/javascript' >
        $(document).ready(function(){ 
                var data = <?php echo($data)?>;

Can you spot what/where the missing element is? 你能发现丢失元素的位置/位置吗? I have been trying to figure this out for a few hours and it has me stumped. 我一直试图弄清楚这几个小时,这让我很难过。 Being new to javascipt and jquery does not help either :) 对javascipt和jquery不熟悉也无济于事:)

Your property names are numeric - that is not valid JavaScript. 您的属性名称是数字 - 这不是有效的JavaScript。 Try renaming the top level properties or making them strings. 尝试重命名顶级属性或使其成为字符串。

These are all valid replacements: 这些都是有效的替代品:

{ 
    _0: [ ...

{ 
    number0: [ ...

{ 
    '0': [ ...

But honestly it is always best to make the property names quoted strings to avoid issues like this. 但老实说,最好将属性名称引用字符串以避免这样的问题。

This will work better: 这会更好:

{ 
"0": [ 
    { "Status" : "example status 2"
    , "Contact ID Number" : "1"
    , "Date Entered" : "2011-06-15"
    , ...

Use PHP's built-in json conversion functions, it will save you pain. 使用PHP的内置json转换函数,它将为您节省痛苦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM