Miomir Dancevic
Miomir Dancevic

Reputation: 6852

Show data from API on page load Jquery

I'm trying to display data from API on page load, but I see in the network tab I got a call but the problem is it does not show in HTML, I don't 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);
        }
    });
});

Upvotes: 0

Views: 860

Answers (1)

Muhammad Omer Aslam
Muhammad Omer Aslam

Reputation: 23738

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.

Upvotes: 2

Related Questions