javascript - How can i fix this getJSON method()? -
I have an exercise that I want to use the getJSON method to display information from the html page!
Below is my code js. And I do not know how to fix it. .
$ (document) .ready (function () {$ ('# id-a a'). Click (function () {var url = "http: //headers.jsontest Com / "; $ .getJSON (url, function) {$ ('# content') empty (); $ .eE (data, function (entry index, entry) {var html = '& lt; div class = "Entry" & gt; 'html =' & lt; div class = "language" & gt; '+ + [[Accept-language]]' '& lt; / div & gt;'; html; = '& lt ; Div class = "host" entry ['host'] + '& lt; / div & gt;'; html + = ' Please help me! Thanks!
Use the data ['accept-language'] instead of entry ['accept' Language '] . And $ Delete each , because it will not lose through the objects, keys.
HTML
& lt; Div id = "id-a" style = "width: 200px; height: 100px; range: 1px solid # 000" & gt; & Lt; A href = "#" & gt; Click me & lt; / A & gt; & Lt; / Div & gt; & Lt; Div id = "content" style = "width: 200px; height: 100px; range: 1px solid # 000; margin-top: 30px;" & Gt; & Lt; / Div & gt;
SCRIPT
& lt; Script & gt; $ (Document) .ready (function () {$ ('# id-a a'). Click (function (e) {e.preventDefault (); var url = "http://headers.jsontest.com/ "; $ .getJSON (URL, function (data) {$ ('# content') empty (); var html = '& lt; div class =" entry "& gt;' html; = '& lt; div class = 'Language' & gt; '+ [[Accept-language'] + ''; html + = '& lt; div class = "host" & gt;' + data [ Host '] +' & lt; / Div> '; html + =' gt; 'html' = '& lt; / div & gt; ; '; // html + =' & lt; / div & gt; '; // it is not needed, there There are no initial tags for this div. $ ('# Content'). Attachment (html);}); // No need to use E.preventDefault;) Instead // return false;} )}} & Lt; / Script & gt;
Comments
Post a Comment