getjson

How to check whether the given object is object or Array in JSON string

拈花ヽ惹草 提交于 2019-11-27 20:41:46
I am getting JSON string from website. I have data which looks like this (JSON Array) myconf= {URL:[blah,blah]} but some times this data can be (JSON object) myconf= {URL:{try}} also it can be empty myconf= {} I want to do different operations when its object and different when its an array. Till now in my code I was trying to consider only arrays so I am getting following exception. But I am not able to check for objects or arrays. I am getting following exception org.json.JSONException: JSONObject["URL"] is not a JSONArray. Can anyone suggest how it can be fixed. Here I know that objects and

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

心不动则不痛 提交于 2019-11-27 18:04:39
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 in as options instead of GET/Url. Here is an example of what we are trying to do that works fine in fiddler; how can I replicate this with the AJAX function? GET /Service.svc/logins/gdd53535342/houses/vxcbdfsdg/people/dsgsdggd?format=json HTTP/1.1 User-Agent: Fiddler Authorization: Basic rgbg423535fa23y4436 X-PartnerKey: df3fgeg-g5g6-b55b-f3d2

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

随声附和 提交于 2019-11-27 17:43:21
My script currently looks like this: <script type="text/javascript"> function updateMe(){ var x = 0; var jsonstr = '{"date":"July 4th", "event":"Independence Day"}'; var activity=JSON.parse(jsonstr); while(x<10){ date = document.getElementById("date"+x).innerHTML = activity.date; event = document.getElementById("event"+x).innerHTML = activity.event; x++; } } </script> Where date"x" and event"x" are a series of html tags. This function runs when the page loads (onload). My goal is to do this exact same thing, only from a local .json file as opposed to the hard code that I've got above. I've

How to read json response as name value pairs in JQuery

☆樱花仙子☆ 提交于 2019-11-27 16:38:28
问题 I want to read json response as name and value pairs in my JQuery code. Here is my sample JSON response that I return from my java code: String jsonResponse = "{"name1":"value1", "name2:value2"}; in my JQuery, if I write jsonResponse.name1 , I will get value as "value1" . Here is my JQuery code $.ajax({ type: 'POST', dataType:'json', url: 'http://localhost:8080/calculate', data: request, success: function(responseData) { alert(responseData.name1); }, error: function(XMLHttpRequest, textStatus

Wait for multiple getJSON calls to finish

感情迁移 提交于 2019-11-27 14:16:50
问题 I have a loop that makes calls to an API and compiles the results into an array. How do I wait until all of the calls are finished until resuming execution? I see a bunch of answers for how to wait until one call is done, but I don't understand how to check for all of them. If I make a while loop that waits until 'obj' is the correct length, the page just stalls until the calls are done, which is not what I want. Help please? function getData(id) { var thisI = i; var url = "www.whatever.com

getJSON Synchronous

☆樱花仙子☆ 提交于 2019-11-27 13:27:26
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 to receive an array that will be saved to database, and a json call another php to return an array will be used by main.php. $(document).ready(function() { get_from_db(); $('#button_cancel').click(function(){ $.ajax({ url: 'submit_to_db.php', type: 'POST', data: {list_item: selected_from_list}, success: function(result){ ... get_from_db(); } }); });

jQuery getJSON to external PHP page

陌路散爱 提交于 2019-11-27 13:15:38
问题 I've been trying to make an AJAX request to an external server. I've learned so far that I need to use getJSON to do this because of security reasons ? Now, I can't seem to make a simple call to an external page. I've tried to simplify it down as much as I can but it's still not working. I have 2 files, test.html & test.php my test.html makes a call like this, to localhost for testing : $.getJSON("http://localhost/OutVoice/services/test.php", function(json){ alert("JSON Data: " + json); });

jQuery.getJSON not working properly in IE8 with gdata json-c. Why? [duplicate]

戏子无情 提交于 2019-11-27 12:57:00
This question already has an answer here: How to make cross-domain AJAX calls to Google Maps API? 1 answer Using jQuery: $.getJSON('http://gdata.youtube.com/feeds/api/videos/b2-5GSjZvW8?v=2&alt=jsonc', function(meta){alert(meta.data.title);}); Firefox and Chrome both work as expected, but IE keeps triggering the error function (when using $.ajax ) instead of success. The error status is "0" which doesn't help much. I've also tried using $.ajax with cache:false to no avail. Any ideas? I can't tell you if it's an error in jquery or IE, but it looks like the XDomainRequest fails in IE. Add this

How to return a value from a function that calls $.getJSON?

房东的猫 提交于 2019-11-27 08:44:55
function lookupRemote(searchTerm) { var defaultReturnValue = 1010; var returnValue = defaultReturnValue; $.getJSON(remote, function(data) { if (data != null) { $.each(data.items, function(i, item) { returnValue = item.libraryOfCongressNumber; }); } }); return returnValue; } Why is the returnValue from this function alway equal to the default value set at the beginning of the function and never to the value retrieved from the JSON lookup? This happens because that callback function ( function(data) {...} ) runs later when the response comes back...because it's an asynchronous function. Instead

Using jQuery's getJSON method with an ASP.NET Web Form

倖福魔咒の 提交于 2019-11-27 07:42:06
How do I go about calling a method on an ASP.NET Web Form page using the getJSON method on jQuery? The goal is this: User clicks on a list item The value is sent to the server Server responds with related list of stuff, formatted using JSON Populate secondary box I don't want to use an UpdatePanel, I've done this hundreds on times using the ASP.NET MVC Framework, but can't figure it out using Web Forms! So far, I can do everything, including calling the server, it just doesn't call the right method. Thanks, Kieron Some code: jQuery(document).ready(function() { jQuery("#<%= AreaListBox.ClientID