Results 1 to 2 of 2

Thread: Urgent: how to use ajax with json

  1. #1
    Join Date
    May 2011
    Posts
    2

    Exclamation Urgent: how to use ajax with json

    hi
    i am currently do a project
    i need to use an json but i am ask to put the json format with the data into a dummy html page
    how am i going to do that?
    cause i need it to use later with the ajax, so i take the html url and put it in
    however i need to only retrieve two attribute...so how to embedded the json in the html so that i can use it in ajax to retrieve two attribute (eg title and publisher)
    Code:
    ["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
    Join Date
    May 2011
    Posts
    38
    What I do is just write the json data to a .js file and link it in the page you need it in.

    Note that you will have to assign that data to a variable:
    Your JSON data doesn't look right to me though, but I don't really know.

    Ex:

    <script type="text/javascript">

    var J = {"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."}};


    alert(J['book']['title']);

    </script>

Similar Threads

  1. Question about JSON
    By jp504 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 14 Mar 2011, 01:03 AM
  2. AJAX, JQuery, JSON with api help needed please.
    By prionkor in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 21 Dec 2010, 07:43 AM

Posting Permissions

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