Tag: getjson

jQuery.getJSON:如何避免每次刷新时请求json文件? (高速缓存)

在此示例中,您可以看到生成的HTML列表。 每次刷新时,脚本都会请求数据文件(ajax / test.json)并再次构建列表。 生成的文件“ajax / test.json”是静态缓存的。 但是如何在每次刷新时避免请求此文件? // source: jquery.com $.getJSON(‘ajax/test.json’, function(data) { var items = []; $.each(data, function(key, val) { items.push(” + val + ”); }); $(”, { ‘class’: ‘my-new-list’, html: items. }).appendTo(‘body’); }); 这不起作用 : list_data = $.cookie(“list_data”); if (list_data == undefined || list_data == “”) { $.getJSON(‘ajax/test.json’, function(data) { list_data = […]

‘jQuery.getJSON’无法在Internet Explorer 8中运行

我正在使用jQuery.getJSON来获取Facebook好友列表,但我没有得到它。 它在Firefox和Chrome中运行良好,但在Internet Explorer 8中无效。 jQuery.getJSON(“https://graph.facebook.com/me/friends?access_token=”+aToken, function(data) { alert(data); } ); 在做了一些研究后,我也尝试了这段代码: jQuery.ajax({ url:”https://graph.facebook.com/me/friends?access_token=”+aToken, type: ‘json’, success: function(json) { alert(json); } });

JSON +的Javascript / jQuery的。 如何从json文件导入数据并解析它?

如果我有一个名为names.json的JSON文件: {“employees”:[ {“firstName”:”Anna”,”lastName”:”Meyers”}, {“firstName”:”Betty”,”lastName”:”Layers”}, {“firstName”:”Carl”,”lastName”:”Louis”}, ]} 如何在javascript中使用其内容?

如何在jquery中获得406错误(不可接受)

我在my.js中进行error handling,我正在对其他服务器进行跨域调用,对于动态HTML模板,我正在使用Mustache.js。 $.getJSON(url, function(data, textStatus, xhr) { $.each(data, function(i, data) { introPage(data); }); }).fail(function(Error) { alert(Error.status); }); function introPage(data ) { $.getJSON(‘myphp.php?jsoncallback=?&template=’+testTemplate, function(msg) { // my operations }).error(function(data) { }); } 我们在getJSON中有.fail()来捕获getJSON中的错误。 我能够捕获404错误(未找到)但是当遇到406错误(不接受或说无效输入)或401错误(未经授权的访问)时,.fail()似乎不起作用 但在控制台中抛出错误 当我点击链接时。 它以下面的格式显示jquery回调中的错误 jQuery191014790988666936755_1378113963780({ “error”: { “code”: 406, “message”: “Not Acceptable: Sorry, There are no results to display for the given input.” […]

如何从数据库中获取基于级联下拉列表选择值的属性值?

我想根据从级联下拉列表中传递所选项目的ID来获取实体的属性…在级联下拉列表的级别1或级别2中的每次更改时,必须更新价格。 我已经实现了级联下拉列表。 当我从第1级选择任何项目时,页面加载Leaguedropdown(第1级)填充和第二个LeagueDivisiondropdown(第2级)填充。我必须实施价格计算器 ,它应根据级联下拉列表中的选定项目计算价格值,所有价格均为存储在数据库中,我正在使用Entity Framework。 我正在使用.change()方法并发送Level 2的getJson请求,它正常工作。 我也想在Level 1上使用相同的function,但我已经使用.change()方法来填充LeagueDivision,所以我也不知道如何在Level 1上实现它。 如果有人指导我并感激,我将不胜感激。 这是视图和脚本 @using (Html.BeginForm(“PriceCalculatorIndex”, “PriceCalculator”, FormMethod.Post, new { enctype = “multipart/form-data” })) { @Html.LabelFor(m => m.SelectedLeague, new { @class = “control-lebel” }) @Html.DropDownListFor(m => m.SelectedLeague, Model.LeagueList, new { @class = “form-control” }) @Html.ValidationMessageFor(m => m.SelectedLeague) @Html.LabelFor(m => m.SelectedLeagueDivision, new { @class = “control-lebel” }) @Html.DropDownListFor(m […]

从getJSON函数返回值

我有一个jquery getJSON函数,我需要返回结果值(在其他地方使用它) 这是代码: function getval(){ jQuery.getJSON(‘http://data.mtgox.com/api/1/BTCUSD/ticker?callback=?’, function(data) { // We can’t use .return because return is a JavaScript keyword. return data[‘return’].avg.value; }); } $(function () { $(document).ready(function() { alert (getval()); }); }); 这是行不通的:( 我知道我可以从getJSON函数内部调用外部函数,其值如下: jQuery.getJSON(‘http://data.mtgox.com/api/1/BTCUSD/ticker?callback=?’, function(data) { // We can’t use return because return is a JavaScript keyword. mysecondfunction(data[‘return’].avg.value); }); function mysecondfunction(value){ //use the value […]

SetTimeOut Timer中的JQuery GetJSON

任何人都可以发布一个示例代码,其中有一个正在运行的计时器(javascript settimeout)并进行数据检索。 基本上我的这个计时器做的是显示新消息.. myFunction(param){ //data retrieval operation //using getJSON.. call displaydata() base on param settimeout(“myFunction()”, param, 1000); } function displaydata(param){ //processing alert(‘test’)} 我应该使用getJSON吗? 我认为这是异步调用的问题..

如何使用jQuery访问多维JSON数组中的值

所以我用getJSON获取一个多维JSON数组,我希望访问数组中的值,但是不能超过数组中的第一个元素。 “producers”, [ { “producer”:{ “id”:”1″, “name”:”Em\u00e5mejeriet”, “address”:” Grenv\u00e4gen 1-3″, “zipcode”:” 577 39″, “district”:” Hultsfred”, “webpage”:”http:\/\/www.emamejeriet.se”, “logoURL”:”..\/producenter\/images\/ema.png”, “latitude”:”57.4999″, “longitude”:”15.828″ } }, { “producer”:{ “id”:”2″, …等等。 我的代码: $.getJSON(“/url/producers.json”, function(data) { $.each(data, function() { $.each(this, function(key, value) { console.log(value.producer); }); }); }); 输出是一个对象,我不知道更好的粘贴方法,从浏览器控制台复制:“ > Object {id: “1”, name: “Emåmejeriet”, address: “Grenvägen 1-3, zipcode: “577 39”, disctrict: “Hulsfred”…} […]

使用本地文件的jQuery的.getJSON在Firefox 3.6.13上停止工作

突然之间,使用jQuery的.getJSON进行本地文件访问对我来说不适用于Firefox(3.6.13)。 我知道在Chrome中使用它的问题 – 使用Chrome中的本地文件的jQuery getJSON问题 。 使用选项–allow-file-access-from-files修复了该问题。 我现在拥有适用于IE,Chrome(如上所述)并且曾经在Firefox上工作的代码,直到现在。 给你一些背景: // get the only json file var script = _.detect($(‘script’).toArray().reverse(), function(script) { return script.type === ‘application/json’; }); // script.src is now ‘../../json/foo/foo1.json’ return $.getJSON(script.src, function(json) { alert(‘hello’);// says ‘hello’ in IE, Chrome (with arg), used to work in Firefox }); 具体来说,正如小代码片段所示,.getJSON调用无法返回并说’hello’ – 有问题的json文件位于本地文件系统上(例如file:///d/foo/bla.json)。 JSON传递JSONLintvalidation器。 我已经尝试禁用所有插件 – […]

通过jQuery Ajax发送Json数组

我将通过jquery ajax调用发送一个json对象数组到一个php文件。 var arr = new Array(); var record1 = {‘a’:’1′,’b’:’2′,’c’:’3′}; var record2 = {‘d’:’4′,’e’:’5′,’f’:’6′}; arr.push(record1); arr.push(record2); 如何通过jquery ajax发送数组? 我怎样才能在php中获取值? 谢谢。