R
R
Roman2016-04-21 22:29:00
JavaScript
Roman, 2016-04-21 22:29:00

Why json data is not displayed using AJAX?

JSON data should be displayed from a remote server via AJAX, but for some reason nothing is displayed.
In the developer console, the data appears in the resources, just after the function is executed, but nothing appears in the browser window.
I use chrome, I run it in non-security mode (with the --disable-web-security line). Tried in other browsers, the same shnyaga.
What's the problem, guys?

I am using a query like this:

$.ajax({
     url: "http://oamk.fi/~vetapani/persons.json?jsoncallback=?", 
        dataType: 'json',
        data: { format: 'json' },
        success: function(data) {
            $("#list").append("test1");
            $.each(data, function () {
                $("#list").append("<p>");
                //loop
                $.each(this, function (name, value) {
                    if(name==="name") {
                          $("#list").append(value+ " ");
                     }
                     if(name==="email") {
                           $("#list").append(name+': <a href="mailto:'+value+'">'+value+'</a>');   
                     }
               });
               $("#list").append("</p>");
          });
     }
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maa-Kut, 2016-04-21
@Maa-Kut

We put a breakpoint inside the success function and see if the debugger drops out on it. If not, we look at the network request log, maybe there is some kind of HTTP 500. If yes, then either the response is parsed incorrectly (it did not come in the format expected), or there is a jamb with the layout (is the #list element definitely present?).

N
Ninja Mate, 2016-04-21
@victorzadorozhnyy

set the request type to GET/POST, to success console.log(data) and to error too. there must either get an error or a result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question