SitePoint Sponsor

User Tag List

Results 1 to 21 of 21

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation URENTGLY:why is there sytnax error

    hi anyone know why there is syntax error to this?
    if i write this can i get a attribute frm the json file?
    is it because how i put the json data in html wrongly?

    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5

    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {

    var addrField = document.getElementById("myDiv");
    var card = eval('('+xmlhttp.responseText+')'); // they say the error is here
    addrField.value = card.places.place.name.value;
    }
    }

    xmlhttp.open("GET","HTMLPage3.htm",true);
    xmlhttp.send();
    this is my json file in html
    {"books:{
    `"book":[

    {
    "title":"JavaScript, the Definitive Guide",
    "publisher":"O'Reilly",
    "author":"David Flanagan",
    "cover":"/images/cover_defguide.jpg",
    "blurb":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
    },


    {
    "title":"DOM Scripting",
    "publisher":"Friends of Ed",
    "author":"Jeremy Keith",
    "cover":"/images/cover_domscripting.jpg",
    "blurb":"Praesent et diam a ligula facilisis venenatis."
    },

    {
    "title":"DHTML Utopia: Modern Web Design using JavaScript & DOM",
    "publisher":"Sitepoint",
    "author":"Stuart Langridge",
    "cover":"/images/cover_utopia.jpg",
    "blurb":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit."

    }
    ]
    }
    }

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Paste the JavaScript code in the online lint, and you will be shown the problem.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Paste the JavaScript code in the online lint, and you will be shown the problem.
    i check le..yes i miss out one semicolon but still it still give me sytnax error
    is it because i didn't put correctly the json in the html
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title>Untitled Page</title>
    </head>
    <body>
    {
    places:
    {
    place:
    {
    id: "1",
    name: "club",
    x_coordinate: "35484.66533355533",
    y_coordinate: "31293.823929446196"
    }
    {
    id: "2",
    "name": "Police Station",
    x_coordinate: "35951.524906914485",
    y_coordinate: "31862.739419191174"
    }


    }
    }

    </body>
    </html>

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by cutexxbaby View Post
    is it because i didn't put correctly the json in the html
    Yes it is. The html file is intended to be interpreted by a web browser. It's not valid for an html file to be interpreted as json data.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Yes it is. The html file is intended to be interpreted by a web browser. It's not valid for an html file to be interpreted as json data.
    u mean that i cant use this html url to be retrieve data in xmlhttp.open("GET","HTMLPage3.htm",true);
    what i mean was HTMLPage3.htm store the json data in the html and i got to use this url to work with the ajax
    it jus retrieve the name and coordinates

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Let me try to explain this using different words, so that they might be understood.

    The entire contents of the html file will be returned as data to the request. If you want the data to be interpreted as json data, the entire contents of the file must be json data.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Let me try to explain this using different words, so that they might be understood.

    The entire contents of the html file will be returned as data to the request. If you want the data to be interpreted as json data, the entire contents of the file must be json data.
    so is json file then can retrieve?
    okay then why my supervisor say create a dummy html page with the json format data...what she mean that

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by cutexxbaby View Post
    okay then why my supervisor say create a dummy html page with the json format data...what she mean that
    You may have to ask for further clarification from your supervisor on that.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    You may have to ask for further clarification from your supervisor on that.
    okay if i use the json file right ...then it shld be able to get the name and coordinate but how to write in ajax ?then i will like to ask is my format of json declare wrongly?

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by cutexxbaby View Post
    okay if i use the json file right ...then it shld be able to get the name and coordinate but how to write in ajax ?then i will like to ask is my format of json declare wrongly?
    Yes it is. The correct format is shown in diagrams over at the JSON web site.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #11
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    First of all, fix up the most important problems with your code.
    Paste the javascript in to the online lint and fix the problems that it finds there.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #12
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    First of all, fix up the most important problems with your code.
    Paste the javascript in to the online lint and fix the problems that it finds there.
    i use the same ajax way to retrieve data and pin on the point it way ...it just that the border container don't work

    so i not how to make it work can help me please!!!

  13. #13
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    First of all, fix up the most important problems with your code.
    Paste the javascript in to the online lint and fix the problems that it finds there.
    so how is it ? do you know how to work with the border container?

  14. #14
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by cutexxbaby View Post
    so how is it ? do you know how to work with the border container?
    Once the most significant problems with the code are sorted out, we can then focus on the issue at hand without being distracted by other problems.
    Things like automatic semicolon insertion is known to cause unexpected problems with your code, so don't rely on it.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  15. #15
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Once the most significant problems with the code are sorted out, we can then focus on the issue at hand without being distracted by other problems.
    Things like automatic semicolon insertion is known to cause unexpected problems with your code, so don't rely on it.
    so ?? i put the semi colon in liao le ..also can not work...cause i return the bc.domNode ...but it say domNode null ...is it i put at the wrong area or what why the ajax can retrieve data but can't put inside the border container...please help me solve it...

  16. #16
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by cutexxbaby View Post
    so ?? i put the semi colon in liao le ..also can not work...cause i return the bc.domNode ...but it say domNode null ...
    You may need to look somewhere else to find someone who knows about dojo-specific problems.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •