简体   繁体   中英

JSON response from URL

Hey I'm trying to retrieve data from a json file I have hosted on my server but it's not working, I'm not sure what is wrong as I'm not the most well versed in this topic. Any tips are appreciated!

$(document).ready(function () {
$("#button").click(function () {
    $.getJSON({
        type: "POST",
        url: "some URL will go here",
        success: function (result) {
            $("#div1").append(result);
        }
    });
});
});

heres the fiddle as well: http://jsfiddle.net/ahuston12/E5SzH/

Open a modern browser like Firefox or chrome and open the developer tools. Navigate to the page that contains the above code and monitor the "network" tab to see the related http request triggered via ajax. You can then see the request + response including header, body and return codes. This should help to figure out the problem.

You should show us what's going on the server side. It doesn't seems to be problems on this jquery code so i guess it's from server.

You can check the response value to see the problem : on chrome ctrl+j -> network. You'll see your request, click on it to see details like the server's response.

If you have FireBug installed in your Mozilla Firefox open it, in that you can see Net Tab . If you click that you can able to see what kind of response you are getting. I ahve attached the Image For your reference. And for getting a JSON result use "result.d".

Ajax响应图像

The url that you are using doesn't return a json response, it returns a javascript file that charge a json result into a variable, because of that you can't get the result.. if you try with other site that returns information in json format like this you are going to get the data:

$.getJSON("http://headers.jsontest.com/", function (result) {
            console.log(result);
        }
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM