Fabian Steinkogler Fabian Steinkogler - 2 months ago 18
JSON Question

Get and parse a JSON-String from URL

How can i get this json-data-string as an variable and parse it into some usefull fromat?

The url for the string:
http://intranet.ooelfv.at/webext2/getjson.php?scope=laufend&callback=?

Iam pretty new to js and json so some advice on how to get into this topic would be great.

Thank you,
Stoani

Answer

Here's a simple runable example that just logs the content of the data to your console

<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function getData(jsonp){
        console.log(jsonp);
    }

    var scripts = document.createElement('script');
    scripts.src = 'http://intranet.ooelfv.at/webext2/getjson.php?scope=laufend&callback=getData';
    document.body.appendChild(scripts);
</script>
</body>
</html>

You can access the data by modifying the getData function. For example, to get the title, you can use

function getData(jsonp){
    console.log(jsonp.title);
}