SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  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,682
    Mentioned
    99 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,682
    Mentioned
    99 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,682
    Mentioned
    99 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,682
    Mentioned
    99 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,682
    Mentioned
    99 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
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    arh ...i am sorry i don't really get the diagram...can help me see
    {
    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"
    }


    }
    }

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by cutexxbaby View Post
    can help me see
    You have two different places there.
    Shouldn't each place be separated by a comma, and shouldn't yoiu use an array to contain multiple items, such as those places?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  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
    You have two different places there.
    Shouldn't each place be separated by a comma, and shouldn't yoiu use an array to contain multiple items, such as those places?
    oh that one is okay already but can i ask you using ajax right how am i goin to put the data retrieve from the json data into the programmatic dojo border container...i try out but it don't work
    this is one code...i not sure why it don't work in the border container...the htmlpage4 is json data inside
    function getInfoContent(graphic) {

    function ajaxRequests() {
    var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
    if (window.ActiveXObject) { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
    for (var i = 0; i < activexmodes.length; i++) {
    try {
    return new ActiveXObject(activexmodes[i])
    }
    catch (e) {
    //suppress error
    }
    }
    }
    else if (window.XMLHttpRequest) // if Mozilla, Safari etc
    return new XMLHttpRequest()
    else
    return false
    }

    var mygetrequests = new ajaxRequests()
    mygetrequests.onreadystatechange = function() {
    if (mygetrequests.readyState == 4) {
    if (mygetrequests.status == 200 || window.location.href.indexOf("http") == -1) {
    var bookss = eval("(" + mygetrequests.responseText + ")") //retrieve result as an JavaScript object
    var rssent = bookss.infos.info
    for (var i = 0; i < rssent.length; i++) {

    // alert(mygetrequests.responseText);
    var placeImg = ""
    var txt = ""
    // placeImg += rssent[i].descImg
    txt += rssent[i].desc
    var shorttxt = ""
    shorttxt += txt.substring(0, 30);
    var bc = new dijit.layout.BorderContainer({ style: "font-size: 11pt; height: 574px; width:739px; border:0px;" });
    var c1 = new dijit.layout.ContentPane({

    region: "top",
    style: "height: 11.5%; width: 100%; color: black; background-color: transparent; border:0px;",
    content: "<table><div id = \"mydiv\">" + shorttxt + "<font color = '#0000FF' size = '1'><a onclick='showmore();'><u> More...</u></a></div></td></table>"
    });
    bc.addChild(c1);





    }

    }

    else {
    alert("An error has occured making the request")
    }

    }
    return bc.domNode;
    }

    mygetrequests.open("GET", "HTMLPage4.htm", true)
    mygetrequests.send(null)
    }

  14. #14
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by cutexxbaby View Post
    into the programmatic dojo border container...
    What on earth is a programmatic dojo border container?
    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
    What on earth is a programmatic dojo border container?
    this kind var bc = new dijit.layout.BorderContainer({ style: "font-size: 11pt; height: 574px; width:739px; border:0px;" });
    instead of the div ...
    so why it the border container cannot work but if i alert each of the retrieve it call the data but the border container cannot work ...please help me!!!!!

  16. #16
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 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

  17. #17
    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!!!

  18. #18
    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?

  19. #19
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 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

  20. #20
    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...

  21. #21
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 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
  •