Search code examples
javascriptjqueryarraysjsongetjson

JQuery : How get Json Key And Value by and this append (insert into ) list (ul)?


Please take a look at this jsFiddle: http://jsfiddle.net/xY7tx/3108/

When I run getJSON in the above sample, why is the fail part always triggered?

I would really appreciate if one tell me how with jQuery (or even with pure Javascript) How could get the key and value of the JSON file.

My goal is after getting the key (title) and the value (video_url) then insert them all into a list ul which the items of the list are the keys and the href are their values. Thanks


Solution

  • Because it's not JSON data. You're getJSONing an HTML page.

    Try it with the following link:

    $.getJSON("https://raw.githubusercontent.com/xldrx/kodi-persian-contents/master/movies/movies.json", function(d) {
            console.log(d);
        }).fail( function(d, textStatus, error) {
            alert("getJSON failed \n , status: " + textStatus + "\n "+ ", error: "+error + "\n")
        });
    

    As for the list, not sure I fully understood your requirement, but is this what you're looking for: https://jsfiddle.net/p77ymjgx/ ?