0

I have already get the json data from the link and let it become a table, but now I wanna sort it by name, type, weight, birthday. How can I do that? Is there any existing resource I can use?

<div id="id01"></div>
<script>
    $.ajax({
        url: "https://tasks.inlogik.com/devtest/animals",
        dataType: 'jsonp',
        data: '',
        jsonp: 'callback',
        success: function (arr) {
            var out = "<table>";
            out += "<tr><td>"+"Name"+"</td><td>"+"Type"+"</td><td>"+"Weight"+"</td><td>"+"Birthday"+"</td><td>"+"Horns?"+"</td><td>"+"Action";
            for (var i in arr) {
                out += "<tr><td>" +
                    arr[i].name +
                    "</td><td>" +
                    arr[i].type +
                    "</td><td>" +
                    arr[i].weight +
                    "</td><td>" +
                    arr[i].birthday+
                    "</td><td>" +
                    arr[i].hasHorns +
                    "</td><td>" +
                    "Details" +
                    "</td><tr>";
            }

            out += "</table>";

            document.getElementById("id01").innerHTML = out;
        },
        error: function (jqXHR, textStatus, ex) {
            alert(textStatus + "," + ex + "," + jqXHR.responseText);
        }
    });
</script>
  • See https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS about cross-origin. A web application using XMLHttpRequest could only make HTTP requests to the domain it was loaded from. – dreyescat Nov 22 '14 at 08:20

1 Answers1

0

Problem is

XMLHttpRequest cannot load your https://tasks.inlogik.com/devtest/animals. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access.

An XMLHttpRequest to a different domain than your page is on. So the browser is blocking it as it usually allows a request in the same origin for security reasons. You need to do something different when you want to do a cross-domain request. Refer this Link

Mark me If this Helpful to You

Community
  • 1
  • 1
satyaraju
  • 1
  • 1