hi i am doing on a project i need to use the json format for the data but i am ask to put the json in the html after that use ajax and call into the javascript function anyone know how can i put the json in html and how to use ajax this is my json data
`["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."
}
]`
JSON is a subset of Javascript syntax.
You can write
var myArray = [ { prop: 123 }, ... ];
Ok, so what it sounds like you want is just to be able to see What's returned by an AJAX call without doing any logic on the page itself.
Simply doing this:
json.html:
<html>
<head><title>My JSON</title></head>
<body>
{
"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]}
}}
</body>
</html>
And when you call your ajax function, the content of the page will be returned.