Tag: json

使用JSON数据填充下拉菜单

我正在使用AJAX来根据另一个下拉列表的选择来填充下拉框。 我在这里使用了jQuery的教程 – http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/并更改了选择框名称中的选择框ID名称在脚本中。 当主复选框的值发生变化时,发送ajax并返回如下: {“1″:”Kieran Hutchinson”,”2″:”Caleb Tan”,”3″:””} 这与教程代码中返回的JSON字符串略有不同,如下所示 [{optionValue:10, optionDisplay: ‘Remy’}, {optionValue:11, optionDisplay: ‘Arif’}, {optionValue:12, optionDisplay: ‘JC’}] 我认为这是问题,但我不知道如何从我的JSON响应中获取正确的值。 javascript如下: $(function(){ $(“select#ContactCompanyId”).change(function(){ $.getJSON(“contactList”,{id: $(this).val(), ajax: ‘true’}, function(j){ var options = ”; for (var i = 0; i < j.length; i++) { options += '’ + j[i].optionDisplay + ”; } $(“select#QuoteContactId”).html(options); }) }) }) 提前致谢

显示一些错误未捕获的ReferenceError:

我有一个json文件,并显示一些错误,请你帮我 显示错误Uncaught ReferenceError: marketlivedata is not defined Data Call to json // ===================== $(document).ready(function(e) { // alert(‘hello’); // var marketlivedata ; }); // ===================== function getUserData() { $.ajax({ type: “GET”, url: “http://xxxxxxxxx.xxxxxxx.com/xxxxxxx.json”, dataType: ‘jsonp’, crossDomain: true, success: function(data) { // $(‘#ajexLoaderSec’).hide(); console.log(data); }, error: function(e) { alert(“There is an error while connecting to the server. […]

使用我的json数据填充JQuery DataTable

我建议使用JQuery数据表。 现在我需要使用从我的控制器发送的一堆json对象来填充网格。 如何从js在网格上发送此数据 $.ajax({ … url: ‘/Home/ReturnJsonData’, success: function (result) { $.each(result, function (i, item) { // this is where I should sent item object to my grid }); }, error: function () { alert(“error”); } }); 更新我发现了这些链接 ,但我不知道如何实现它。

使用jQuery.parseJSON的JSON解析错误

此代码失败,并显示指示无效JSON的exception: var example = ‘{ “AKEY”: undefined }’; jQuery.parseJSON(example); 我能够通过用空字符串替换所有未定义来修复它。 undefined不是JSON的一部分吗?

如何从jquery脚本中将jSON响应转换为变量

我在下面的jquery脚本遇到问题,这是一个基本的剥离版本,即使它不起作用,我有jquery脚本调用的php文件,我将它设置为编码并显示json响应 然后在jquery脚本中它应该读取值并响应它但它没有得到响应。 json.response是错误的方法来调用名称响应的json字符串中的变量吗? 有人可以帮助我,我被卡住了 ‘error’,’comment’=>’test comment here’); echo json_encode($arr); ?> //the script above returns this: {“response”:”error”,”comment”:”test comment here”} $.ajax({ type: “POST”, url: “process.php”, data: dataString, dataType: “json”, success: function (data) { if (json.response == ‘captcha’) { alert(‘captcha’); } else if (json.response == ‘error’) { alert(‘sorry there was an error’); } else if (json.response == ‘success’) […]

使用jquery使用JSON数据重新填充表单

我有一个HTML表单,我通过ajax保存到数据库。 要获取键/值对的查询字符串,我使用了非常方便的serialize函数,如下所示: var myData = $(“form#form_id”).serialize(); $.ajax({ url: “my_save_script.php”, type: “post”, data: myData, success: function(msg){ alert(msg); } }); 现在我想加载一个空白表单,并使用数据库中的数据重新填充它,该数据从ajax调用作为JSON字符串传递。 我已经能够获得具有正确键/值对的Javascript对象,如下所示: data = $.parseJSON(data); data = data[0]; 重新填充表单最简单,最优雅的方法是什么? 请记住,表单的输入元素是文本,选择,复选框和广播。 输入元素的名称与数据库列的名称相同,并且是上述data对象中键/值对的键。 这就是为什么serializefunction对我来说非常好

使用存储在数组中的备用JSON格式创建动态jstree

我能够使用替代JSON格式创建jstree,如下所示: $(‘#using_json_2’).jstree({ ‘core’ : { ‘data’ : [ { “id” : “ajson1”, “parent” : “#”, “text” : “Simple root node” }, { “id” : “ajson2”, “parent” : “#”, “text” : “Root node 2” }, { “id” : “ajson3”, “parent” : “ajson2”, “text” : “Child 1” }, { “id” : “ajson4”, “parent” : “ajson2”, “text” : […]

超出了JavaScriptSerializer.MaxJsonLength。 处理此问题的最佳做法是什么?

我使用jQuery的$ .ajax()函数向客户端发送了大量数据。 我正在ASP.NET Web服务中调用一个返回JSON数据的方法。 对于大多数搜索来说,一切都很棒,但是当我有一个大型数据集要返回时,我遇到了JavaScriptSerializer MaxJsonLength属性的问题。 处理此问题的最佳做法是什么? 我不想随意设置最大长度。 如果返回的数据大于当前最大值,或者我应该重新写入并向客户端发送数据,我可以在Web服务中设置MaxJsonLength吗? 以下是来自Web服务的相关代码段: Dictionary jsonValuePairs = new Dictionary(); //add some data to the dictionary… return System.Web.Script.Serialization.JavaScriptSerializer.Serialize(jsonValuePairs);

如何使用JSON从Wikipedia API检索数据?

在这里,我使用以下代码从维基百科中获取数据。 但它不适合我。 var playListURL = ‘http://en.wikipedia.org/w/api.php?format=json&action=query&titles=India&prop=revisions&rvprop=content&callback=?’; $.getJSON(playListURL ,function(data) { $.each(data.pages, function(i, item) { alert(i); }); }); DEMO LINK: – http://jsfiddle.net/rushijogle/dyeqy/

将PHP json_encode数组发送到jQuery

好吧,我想我需要帮助! 我搜索了我能想到的每一个关键词,但我仍然无法弄清楚,请帮忙。 我更像是一个php人,我刚开始使用jQuery。 基本上,我想要做的是从点击function发送一个jQuerypost。 并根据我的php函数返回的内容,显示/隐藏2个div。 我的php函数返回一个带有2个简单值的“json_encode”数组,如: // ================== PHP代码============================ ====== $message_for_user = “blah blah”; $calculatedValue = 1230; $responseVar = array( ‘message’=>$message_for_user, ‘calculatedValue’=>$calculatedValue ); echo (json_encode($responseVar)); // ================== PHP代码结束=========================== ======= 我的javascript代码应该接受php返回的值: // ================== Javascript代码============================ ====== $(“div.calculator_result”).click(function() { $.post(‘myCalculator.php’ ,{qid:itemID},function(response) { $(“div.calculation_value”).show(500).html(response[‘calculatedValue’]); $(“div#message_for_user”).show(500).html(response[‘message’]); } } // ================== Javascript代码结束=========================== ======= 不幸的是,在我的项目的javascript方面,div没有更新我的PHP函数返回的值….我在哪里错了? 我希望我的问题清楚,如果没有,请告诉我,我将提供所需的任何额外信息。 另一件事是,早些时候,我只回显一个值,即计算值(echo $ calculatedValue),一切正常,它只是在我转移到json编码数组中的echo之后,事情不起作用