Skip to content Skip to sidebar Skip to footer

Ajax Appearing As Undefined

So I'm currently working on this website app and I'm trying to show how many PC's are available in my University using the JSON from the University website and AJAX. I can't figure

Solution 1:

First in dataType you put 'jsonp' instead of 'json'. And S Jayesh is right, you must stringify to see the answer. See this exemple.

$.ajax({
    url: "blabla.php",
    data: data,
    type: 'POST',
    contentType: "application/x-www-form-urlencoded",
    dataType: 'json',
    error: function(data){
        var err = JSON.stringify(data);
alert(err);
    },
    success: function(data){
        var succ = JSON.stringify(data);
alert(succ);
    }
});

With that structure, you'll see what is the problem. Use post instead of get, it's better.

Solution 2:

To display JSON as string you need to use JSON.stringify() function :

container.append('<div>'+ JSON.stringify(value.displayName) +'</div>');

Post a Comment for "Ajax Appearing As Undefined"