getjson

如何使用jquery处理json数据

a 夏天 提交于 2019-11-30 14:07:09
如摘要所说,json是常用的前后端交互的数据格式,本文简单介绍jquery如何解析json数据,以备忘。 如下是一个嵌套的json: [{"name":"20:00-21:15","price":"1.00"},{"name":"17:30-17:59","price":"1.00"}, {"name":"22:00-22:30","price":"3.00"},{"name":"20:00-21:15&22:00-22:30","price":"0.00"}] 1. 在jQuery中有一个简单的方法 $.getJSON() 可以实现. 下面引用的是官方API对$.getJSON()的说明: 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. 回调函数中接受三个参数

Passing JSON data to .getJSON in jQuery?

旧街凉风 提交于 2019-11-30 13:14:50
问题 I am trying to pass a JSON object to .getJSON but I keep getting a bad request error. This is what I am trying: var data = { "SomeID": "18", "Utc": null, "Flags": "324" }; $.getJSON("https://somewhere.com/AllGet?callback=?", JSON.stringify(data), function (result) { alert(result); }); Currently to get it working, I have to do this, but I do not like how I have to manually construct the query string: $.getJSON("https://somewhere.com/AllGet?SomeID=18&Utc=&Flags=324&callback=?", null, function

Jquery getJSON sorts my data by id automatically

徘徊边缘 提交于 2019-11-30 11:32:38
I have a combo box that triggers a jquery function on change, it calls a php script which brings the results from the database sorted by name not by id (table cities) and creates a json file with the id and the name of the city. The problem comes with a $.getJSON(url, data) function, it retrieves all the json encoded data fine, but it is seems to be sorting the data automatically by the id for instance if the php page generates id name 3 Dania Beach 1 Miami 2 Weston after jquery getJSON it sorts it by id id name 1 Miami 2 Weston 3 Dania Beach Is there a way to disable sorting? or how can in

Retrieve data from JSON file and display images in a gallery

橙三吉。 提交于 2019-11-30 10:32:08
I'm new to JQuery and any help would be much appreciated. "Using $.getJSON function, retrieve the data in the items.json file provided and display the images in a gallery below. The gallery should display each image at roughly thumbnail size with its caption below it in a 3-column grid at desktop resolution." I was able to get the the .json to output on the HTML page, now I was wondering how to get the actual images to show on the HTML page instead of the URL path of the images? This is what outputs to the HTML page currently: URL: images/image_1.jpg caption: Image 1 Caption URL: images/image

JQuery get data from JSON array

ε祈祈猫儿з 提交于 2019-11-30 07:01:13
问题 This is part of the JSON i get from foursquare. JSON tips: { count: 2, groups: [ { type: "others", name: "Tips from others", count: 2, items: [ { id: "4e53cf1e7d8b8e9188e20f00", createdAt: 1314115358, text: "najjači fitness centar u gradu", canonicalUrl: "https://foursquare.com/item/4e53cf1e7d8b8e9188e20f00", likes: { count: 2, groups: [ { type: "others", count: 2, items: [] }], summary: "2 likes" }, like: false, logView: true, todo: { count: 0 }, user: { id: "12855147", firstName: "Damir",

Get a JSON file from URL and display

耗尽温柔 提交于 2019-11-30 06:45:24
问题 The code is very simple, I do not know why it deosnt work. This is the link to the JSON file, http://webapp.armadealo.com/home.json Here is the code using getJSON $.getJSON("http://webapp.armadealo.com/home.json", function(data){ alert(data); }); I just want the code to display the whole JSON content. 回答1: After so many months of search, I found the solution. Hence, I am answering my own question. When JSON is not supported and when we are stuck with Same Origin Policy, we have to wrap around

Escaping JSON apostrophe before PHP's json_encode truncates?

荒凉一梦 提交于 2019-11-30 05:49:05
问题 I have a field in a MySQL database (utf8_general_ci) that contains a curly (smart?) apostrophe: Owner’s... This prints fine with no special handling if I access the PHP page that pulls it from the DB. However, I am trying to access it via a $.getJSON request on another page, so I used PHP's json_encode. It truncates the value so that it reads Owner , then successfully encodes the rest of the data. If I use PHP's utf8_encode on the field before I json_encode, it includes the full value with

Aborting a jQuery getJSON XMLHttpRequest

て烟熏妆下的殇ゞ 提交于 2019-11-30 05:16:44
Turns out this was an artefact of a Firebug bug. The Ajax request was cancelled, but Firebug continued reporting it as active. Details here . I have long running XMLHttpRequests and I need to be able to abort them under certain circumstances. I set up the request in a normal way: ajax = $.getJSON(url + "?updates", function(data) { ...; }); Later on I want to abort this request, seems straightforward: ajax.abort(); When I look in Firebug however, I see it is still running... I console.log out the value of ajax just before I try and abort it, it confirms that its value is and XMLHttpRequest

getJSON vs. optJSON

独自空忆成欢 提交于 2019-11-30 00:24:02
问题 I was looking over the documentation for JSONObject when I noticed the two methods: getJSONObject(String key) and optJSONObject(String key) . From the documentation, I figured they did nearly the same thing with one difference: If the key or value isn't found, then getJSONObject() throws a JSONException whereas optJSONObject() simply returns null . Are there any other differences between getJSONObject() and optJSONObject() ? What are the advantages of get over opt and vice-versa? Are there

$.ajax() and “Uncaught ReferenceError: data is not defined”

大兔子大兔子 提交于 2019-11-29 16:49:48
I tried out several ways to get .json file and data using $.getJSON and $.ajax() overthere My JS code n⁰2 fails : $.ajax({ type: "GET", url: 'js/main.js', data: data, success: 1, }).done(function ( data ) { var items = []; $.each(data.tata.entities.q142.labels.fr.value, function(key, val) { items.push('<li id="' + key + '">Test 2:' + val + '</li>'); }); $('<ul/>', { 'class': 'my-new-list', html: items.join('') }).appendTo('body'); }); In Chrome console, the message error is : "Uncaught ReferenceError: data is not defined" Refering to the line : data: data, What is going wrong ? What to do ?