How to call url in javascript?
You have a url to call http://eclipsewildflyserver-gobanit.com/rest/something/id=1
and that is .json file . Therefore try this.
You can use jQuery .getJSON() function:
$.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20yahoo.finance.quotes%20WHERE%20symbol%3D%27WRC%27&format=json&diagnostics=true&env=store://datatables.org/alltableswithkeys&callback', function(data) {
//data is the JSON string
});
Just replace this url with your relevant url.
M.Redy
Updated on June 14, 2022Comments
-
M.Redy almost 2 years
I´m creating frontend for app and i need to call api function. I've got a url from api, which gives me json data like this:
{ "id": 1, "name": "First Like", "description": "Like at least 1", "image": "images/badges/FIRST_LIKE" }
I need to call some of those items in my website.
<script type="text/javascript"> //url to call http://eclipsewildflyserver-gobanit.com/rest/something/id=1 function getList(){ var name = url.getItem("description"); document.getElementById("name").innerHTML = name.toString(); }
I know im doing this completely wrong, and its my first atempt to do something like this, so I would really apreciate the help. Where should and how should I add url to code so i can pick a items i need? Thanks
EDIT: So i tried to replace with the ideas you gave me, and its still not working. Can anyone tell me what am I doing wrong?
<script type = "texxt/javascript" src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type="text/javascript" language="javascript"> <head> $.getJSON('http://eclipsewildflyserver-gobanit.rhcloud.com/AssignToolWebApp/rest/id=1', function (data) { var name = data; document.getElementById("name").innerHTML = name.toString(); }); </script> </head> <body onload=getList()> <div id="TopHeader"> <div id="header" class="container"> <div id="menu"> <ul> <h1 id="name"></h1> </ul> </div> </div> </div> </body></html>
Just trying to write a JSON string to page. Not working. I guess I´m doing something wrong.