Tag: getjson

JQuery解析JSON数组

我有一个JSON输出,如下所示: [“City1″,”City2″,”City3”] 我想获得每个城市名称,我该怎么做? $.getJSON(“url_with_json_here”,function(json){ }); 编辑: $.getJSON(‘url_here’, function(data){ $.each(data, function (index, value) { $(‘#results’).append(”+value+”); console.log(value); }); }); 以上似乎不起作用,没有输出值。

使用jQuery getJson将列表/数组作为参数发送

我有以下我正在尝试将列表/数组发送到MVC控制器方法: var id = []; var inStock = []; $table.find(‘tbody>tr’).each(function() { id.push($(this).find(‘.id’).text()); inStock.push($(this).find(‘.stocked’).attr(‘checked’)); }); var params = {}; params.ids = id; params.stocked = inStock; $.getJSON(‘MyApp/UpdateStockList’, params, function() { alert(‘finished’); }); 在我的控制器中: public JsonResult UpdateStockList(int[] ids, bool[] stocked) { } 两个参数都是空的。 请注意,如果我将参数更改为单个项目 params.ids = 1; params.stocked = true; public JsonResult UpdateStockList(int ids, bool stocked) { } […]

$ .getJSON在IE中不起作用

我正在使用以下代码从JSON中获取数据。 $(document).ready(function() { $.getJSON(“http://www.xyz.com/data.php?id=113&out=json”, function(data) { $.each(data.issue.page, function(i,item) { imagesJSON[i] = item[“@attributes”]; }); alert(imagesJSON.length); }); }); 它适用于Mozilla,chrome和其他浏览器,但不适用于IE。(不在任何版本中)。

带有超时的jQuery getJSON

当打电话给雅虎网络服务(http://boss.yahooapis.com/ysearch)以返回数据集时,是否可以设置超时并在程序结束后退出例程? jQuery.getJSON(“http://boss.yahooapis.com/ysearch/…etc”, function (data) { //result set here });

jQuery.getJSON不会触发回调

我有一个HTML代码: asd $(‘button’).click( function() { $.getJSON(‘/schedule/test/’, function(json) { alert(‘json: ‘ + json + ‘ …’); }); } ); 和相应的观点: def test(request): if request.method == ‘GET’: json = simplejson.dumps(‘hello world!’) return HttpResponse(json, mimetype = ‘application/json’) 执行视图(使用print测试),初始化json变量但不显示警报。 我做错了什么? 我已经看过一些关于此的文档(例如http://docs.jquery.com/Ajax/jQuery.getJSON#urldatacallback ),但我没有找到答案。 编辑:问题是, HttpResponse没有导入…不幸的是Django没有给出任何错误。 其他一切都是正确的。 问候 CHRISS

使用promises数组和$ .when忽略AJAX错误

我有以下代码从YouTubevideoID数组中获取JSON。 当所有video都存在且查询成功时,它的效果很好。 它发送了几个getJSON请求,当它们全部完成时… $ .when.done()触发,我可以处理结果数据。 var results = {}, promises = []; $(document).ready(function() { var vids = [ ‘ozj2-bnTL3s’, ‘EAZ4Tlt8MQ4’, ‘Xn9o7cxqVoA’ // ,’this-videoid-doesnot-exists’ ], url = ‘http://gdata.youtube.com/feeds/api/videos/{{vid}}?v=2&alt=json’; $.each(vids, function(idx, vid){ var u = url.replace(‘{{vid}}’, vids[idx]), p = null; p = $.getJSON( u ).done(function(data) { results[vid] = data.entry; }); promises.push(p); }); $.when.apply($, promises).done(function(){ console.log(results); }); }); […]

$ .getJSON无效

我在jQuery中搜索相关主题。 但我没有看到任何方法来解决我的问题。 $(document).ready(function(){ $(“#inputForm”).submit(function(event){ $(“:text”).each(function() { var inputText = $(this).val(); var userList = []; var weblink = ‘http://test.com’; // problem is from here. $.getJSON(weblink, function(data){ alert(weblink); // this statement doesn’t show up $.each(data, function(entryIndex, entry){ userList.push(entry[‘from_user’]); }); }); alert(userList); }); }); }); 这里有四个问题: 为什么第一个警报(’weblink’)没有出现。 为什么这段代码无法从网站获取json数据 此代码的目标是从json文件获取from_user标记并存储到userList数组中。 变量在“$ .each(data,function(entryIndex,entry){”语句中,该函数有两个输入参数,一个是entryIndex,另一个是entry,我很奇怪这两个参数是针对什么的?我该如何使用这两个参数。 任何人都可以帮我解决这个问题。 我在这里待了一天。 非常感谢你。

尝试将Google Places API与JQuery的getJSON函数一起使用

这可能是非常基本的,但我正在尝试测试Google Places API。 我正在浏览文档并使用它们提供的一些示例。 我正在尝试使用JQuery getJSON函数,因为我已经能够成功地使用它来异步访问外部JSON文件,所以我认为这可能是获取Google Places查询的JSON结果的好方法。 这是我正在尝试使用的代码: var requestURL = ‘https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=’my_google_places_key’; $(document).ready(function () { $.getJSON(requestURL, function (data) { for (i = 0; i < data.results.length; i++) { myAddress[i] = data.results[i].formatted_address; document.getElementById("message").innerHTML += myAddress[i] + "”; console.log(myAddress[i]); } }); }); 根据文档,对查询的结果JSON响应应如下所示: { “html_attributions” : [ “Listings by \u003ca href=\”http://www.yellowpages.com.au/\”\u003eYellow Pages\u003c/a\u003e” ], “results” : [ { […]

Access-Control-Allow-Origin不允许加载XMLHttpRequest

我正在尝试访问education.com API数据。 但是,我一直收到错误指出的错误: XMLHttpRequest无法加载http://api.education.com/service/service.php?f=schoolSearch&key=mykey&sn=sf&v=4&city=Atlanta&state=ga&Resf=json 。 Access-Control-Allow-Origin不允许使用Origin。 我的代码如下: $(function(){ $.getJSON(‘http://api.education.com/service/service.php?f=schoolSearch&key=mykey&sn=sf&v=4&city=Atlanta&state=ga&Resf=json’, function(data) { console.log(data); }); }); 有谁可以帮助我吗?

jQuery.getJSON在IE8中使用gdata json-c无法正常工作。 为什么?

使用jQuery: $.getJSON(‘http://gdata.youtube.com/feeds/api/videos/b2-5GSjZvW8?v=2&alt=jsonc’, function(meta){alert(meta.data.title);}); Firefox和Chrome都按预期工作,但IE不断触发错误function(使用$.ajax )而不是成功。 错误状态为“0”,这没有多大帮助。 我也试过使用$.ajax和cache:false无济于事。 有任何想法吗?