Tag: json

循环遍历仅以特定模式开头的JSON对象

循环通过仅以特定模式开始的JSON对象的正确/惯用方法是什么? 示例:说我有JSON之类的 { “END”: true, “Lines”: “End Reached”, “term0”: { “PrincipalTranslations”: { // nested data here } }, “term1”: { “PrincipalTranslations”: { // more nested data here } } } 我只想访问PrincipalTranslations对象,我试过: $.each(translations, function(term, value) { $.each(term, function(pos, value) { console.log(pos); }); }); 哪个不起作用,可能是因为我无法遍历END和Lines对象。 我试着用类似的东西 $.each(translations, function(term, value) { $.each(TERM-THAT-STARTS-WITH-PATTERN, function(pos, value) { console.log(pos); }); }); […]

MySql – 未在html中显示的JSON数据

我正在尝试从MySql创建一个下拉列表。 php成功从MySql中获取数据。 但我的问题是我的HTML页面的下拉列表中没有显示数据? json_mysql_data2.php header(“Content-Type: application/json”); require_once(“con.php”); $i=0; $jsonData = array(); foreach ($conn_db->query(“SELECT customerID FROM customers WHERE furniture=’33’ “) as $result){ $i++; $jsonData[“article”.$i]=$result[‘customerID’]; } echo json_encode($jsonData); myJS.js $(document).ready(function(){ var ddlist = document.getElementById(“ddlist”); var hr = new XMLHttpRequest(); hr.open(“GET”, “json_mysql_data2.php”, true); hr.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”); hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200) { var […]

试着在jQuery中使用JSON

我正在尝试让json使用jQuery 1.4.1,但我得到一个null对象。 这是一个不工作代码的例子:(使用带有’success:’的$ .ajax) $.ajax({ url: ‘http://isohunt.com/js/json.php’, dataType: ‘json’, success: function(data) { alert(‘Worked’); alert(data); } }); 这段代码有什么问题? 提前致谢

ajax jquery post方法

我有如下所示的url DataProcessor.aspx的ajax请求,如何编写asp.net c#代码以从请求中提取json数据并在DataProcessor.aspx页面中显示 var json = “{‘ItemName’:'” + escape(item.val()) + “‘,’CategoryID’:'” + category.val() + “‘,’RecordID’:'” + record.val() + “‘}”; alert(escape(item.val())); alert(category.val()); alert(record.val()); var ajaxPage = “DataProcessor.aspx?Save=1”; //this page is where data is to be retrieved and processed var options = { type: “POST”, url: ajaxPage, data: json, contentType: “application/json;charset=utf-8”, dataType: “json”, async: false, success: function(response) […]

在AJAX调用期间接收JSON解析错误

我有一个PHP脚本,它正在创建我的Web应用程序所需的JSON。 我正在使用jQuery的Ajaxfunction从我创建JSON的PHP页面获取JSON。 我发现了一个奇怪的怪癖。 如果我只是在Web浏览器中运行我的PHP文件并输出JSON,然后将该JSON复制到一个名为myJSON.json的文件中,该文件链接到我的Ajax URL调用,我的代码就可以了。 但是,如果我在Ajax URL调用中直接链接到我的PHP文件,则会收到以下错误: Requested JSON parse failed 。 所以这是我的相关PHP代码: getData() as $message) { // `date_received` is in Unix time. Begin converting this to a readable date and convert it to the users timezone $newTZ = new DateTimeZone(“America/Chicago”); // This will be based on the users location during production $currentTime = new […]

jQuery进度条,带有对json的ajax请求

我需要一些关于ajax请求和jQuery进度条中数据使用的帮助。 这是index.html 这是test.json { “progressbar”:12 } 这是JavaScript代码 $(function() { $.ajax({ dataType:”json”, url: test.json, success: , }); $( “#progressbar” ).progressbar({ value: }); }); 对不起,我不习惯jQuery和json。 我很高兴有一个非常好的例子! 非常感谢你!

json数据检查是否重复相同的id

我有一个json数据,其中一个id有不同的color_id。 所以从那里我只想检查同一个id是否重复然后只保留第一个 这是我的示例JSON var data= [{ “id”: “1”, “name”: “xxx”, “age”: “22”,”color_id”: “22” }, { “id”: “1”, “name”: “yyy”, “age”: “15”,”color_id”: “1” }, { “id”: “5”, “name”: “zzz”, “age”: “59”,”color_id”: “22” }]; 我想要的输出 var data= [{ “id”: “1”, “name”: “xxx”, “age”: “22”,”color_id”: “22” }, { “id”: “5”, “name”: “zzz”, “age”: “59”,”color_id”: “22” }]; 我尝试减少但在那里我发现修改数据结构所以我不确定我是否会得到我想要的输出。

使用jquery自动完成我试图获取文本框中的值作为表数据不是来自json使用文本字段中的ajax

这是我第一次使用带有json的ajax进行自动完成(Jquery),结果看起来像是自动完成,但结构(输出)看起来像表。 这是我的jquery代码 $(“document”).ready(function (){ $(function () { $.ajax({ url: “dummy.json”, success: function(){ alert(“got the file”); }, error:function (xhr, ajaxOptions, thrownError){ console.log(xhr.status); console.log(thrownError); } }); return false; }); }); 这是我的json数据 { “schoolname”:{ “school”:[ { “id”:”1″, “description”:”COL000001″, “schoolname”:”Emirates College of Technology- UAE” }, { “id”:”2″, “description”:”COL000002″, “schoolname”:”Al Khawarizmi International College- UAE” }, { “id”:”3″, “description”:”COL000003″, “schoolname”:”Syscoms College” […]

从Javascript片段中获取数据

我有以下Javascript代码段通过参数接收customerID(我将解释发生了什么): function purchaseEntry(customerid) { $(‘customeridfield’).value = customerid; if (approvedAgents()) { e1 = $(‘entrylisttable’); e1.hide(); getExistingDetails(customerid, ‘confirmstatusexistingdetails’); $(‘confirmstatushajjlicenceno’).value = ”; $(‘confirmstatusapproved’).checked = false; e1 = $(‘confirmstatus’); e1.show(); } return false; } function getExistingDetails(customerid, existingdetails) { e1 = $(existingdetails); e1.innerHTML = ‘Loading … ‘; var url = ‘/samex/index.php’; var pars = ‘option=com_directory&view=entry2&customerid=’ + customerid + ‘&format=raw’; new […]

使用下拉菜单加载JSON数据,并使用网站中的新结果刷新div区域

我正在尝试将JSON数据从下拉菜单加载到div区域,该区域将使用新结果刷新,我已经管理以获取数据并在div区域中显示它而不使用下拉菜单,但找不到使用下拉菜单调用所需数据的方法。 下面的代码是从我加载网页时出现的json文件中调出部分json数据,但我需要的是当用户点击下拉菜单并点击任何一个时链接,将显示相关的json数据 $(function loadpc() { $(document).ready(function () { // load json file using jquery ajax $.getJSON(‘PCproducts.json’, function (data) { var output = ”; var count = 1; $.each(data.pc, function (key, val) { output += ”; output += ” + ”; output += ”; output += ” + val.title + ”; output += ” + val.category […]