Miomir Dancevic Miomir Dancevic - 10 months ago 83
jQuery Question

Show data from API on page load Jquery

Im trying to display data from API on page load, but i see in network i got a call but the problem is it does not show in HTML, i dont know where can be the problem, this is what i have for now

HTML

<div id="models"></div>


JS

$(document).ready(function(){
var response = "";
$.ajax({ url: "http://carportal.azurewebsites.net/api/portal/brand?CountryCode=RS",
context: document.body,
success: function(){
var json_obj = $.parseJSON(response);
var output="<ul>";
for (var i in json_obj)
{
output+="<li>" + json_obj[i].Name + "</li>";
}
output+="</ul>";
$('#models').html(output);
}});
});

Answer Source

you are missing the response parameter in the success function that's why simple as that

success: function(){

to

success: function(response){

EDIT

Apart from above the URL throws

Failed to load http://carportal.azurewebsites.net/api/portal/brand?CountryCode=RS: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download