0

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/

12
  • Have you checked that the JSON file is accessible from the outside (e.g., can you open it in a browser)? Commented Jul 18, 2013 at 11:46
  • Did u checked what type of response/ error you are getting. Commented Jul 18, 2013 at 11:47
  • 1
    open the js console (eg. ctrl+shift+j in chrome) and check whether the json resource is loaded. Commented Jul 18, 2013 at 11:47
  • for getting JSOn values use "result.d" Commented Jul 18, 2013 at 11:48
  • the JSON is definitely accessible, I also tried other json files that I know are working and I get the same problem Commented Jul 18, 2013 at 11:49

4 Answers 4

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

It looks like it's not loading properly but I'm not sure why. It doesn't even go to my link it goes to my desktop apparently? gives me back [object Object], Method: Option, Status: Pending
Maybe you can post the link you are trying? What is the HTTP response code?
0

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.

8 Comments

I checked using firebug and chrome and I'm not seeing any net activity oddly enough
So it seems that your ajax is never called.
correct, I'm not sure why maybe it has something to do with my function?
try to put onclick to test. Sily question but do you include jquery on your page ? ^^
yeah I'm just using to google library and I do see that request going out when the page loads but nothing when the button is clicked.
|
0

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 Response Image

8 Comments

When I click my button I'm not getting any net activity? Which might explain why chrome showed it was trying to load a file from my desktop?
@AllanHuston Use mozilla Firefox
I used firefox for firebug but didn't get anything for the response, It didn't like there was any net activity at all except for my ajax request for jquery
You are using $("#button") in Jquery are you using "button" as the id name for button
yeah I was hoping it was something stupid like that but it was one of the first things I checked hah
|
0

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);
        }
    );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.