Questions tagged [getjson]

Load JSON-encoded data from the server using a GET HTTP request.

jQuery.getJSON( url, [data], [success(data, textStatus, jqXHR)] )

url A string containing the URL to which the request is sent.

data A map or string that is sent to the server with the request.

success(data, textStatus, jqXHR) A callback function that is executed if the request succeeds.

1965 questions
198
votes
9 answers

Error handling in getJSON calls

How can you handle errors in a getJSON call? Im trying to reference a cross-domain script service using jsonp, how do you register an error method?
Ajay
  • 6,978
  • 17
  • 53
  • 70
113
votes
3 answers

Uncaught TypeError: Cannot use 'in' operator to search for 'length' in

Uncaught TypeError: Cannot use 'in' operator to search for 'length' in " This is the error I receive when I try to do a $.each to this JSON object : {"type":"Anuncio","textos":["Probando esto","$…
111
votes
7 answers

How to use getJSON, sending data with post method?

I am using above method & it works well with one parameter in URL. e.g. Students/getstud/1 where controller/action/parameter format is applied. Now I have an action in Students controller that accepts two parameters and return a JSON object. So how…
Vikas
  • 22,508
  • 34
  • 110
  • 159
105
votes
7 answers

Is it possible to set async:false to $.getJSON call

Is it possible to set async: false when calling $.getJSON() so that the call blocks rather than being asynchronous?
ACP
  • 32,884
  • 96
  • 217
  • 360
102
votes
7 answers

$.getJSON returning cached data in IE8

I'm playing around with ASP.net MVC and JQuery at the moment. I've come across behavour which doesn't seem to make sense. I'm calling JQuery's $.getJSON function to populate some div's. The event is triggered on the $(document).ready event. This…
Andrew Harry
  • 13,417
  • 16
  • 64
  • 101
81
votes
3 answers

How to set cache false for getJSON in jQuery?

I am using getJSON to fetch the results from server side but facing browser cache problems. I want the cache to be false. I tried using this just before my getJSON call. $.ajaxSetup({ cache: false }) But I am not…
Abhinav
  • 951
  • 2
  • 10
  • 17
76
votes
3 answers

How can I pass request headers with jQuery's getJSON() method?

I need to do a getJSON() request, but how do I pass authorisation and custom headers? I am getting issues that the request header is taking the name, but NOT the values. The URL is being shown through a manual request in fiddler to being inserted…
Berty
  • 763
  • 1
  • 5
  • 5
75
votes
5 answers

JSON string to JS object

I am using a JS object to create graphs with Google visualization. I am trying to design the data source. At first, I created a JS object client-side. var JSONObject = { cols: [{ id: 'date', label: 'Date', type: 'date' }, …
Vinod
  • 29,295
  • 31
  • 91
  • 117
59
votes
3 answers

How do I add items to an array in jQuery?

var list = []; $.getJSON("json.js", function(data) { $.each(data, function(i, item) { console.log(item.text); list.push(item.text); }); }); console.log(list.length); list.length always returns 0. I've browsed the JSON in…
NATO24
  • 898
  • 1
  • 7
  • 14
51
votes
5 answers

load json into variable

I have to do something very simple, but there doesn't seem to be an easy way to do this, as far as I can tell. I just want to load JSON data from a remote source and store it in a global Javascript variable using jQuery. Here's what I have: var…
Aaron
  • 712
  • 3
  • 8
  • 8
41
votes
4 answers

getJSON Synchronous

GOAL: What I'm after is to get data from database and refresh main.php (more evident through draw_polygon) every time something is added in database (after $.ajax to submit_to_db.php). So basically I have a main.php that will ajax call another php…
Fred
  • 545
  • 2
  • 5
  • 12
34
votes
5 answers

How can I get javascript to read from a .json file?

My script currently looks like this: