Tag: json

POST,AJAX和PHP:JSON提交

好的,所以这是我的JS / jQuery代码,我的rate.php文件中只有一个print_r($_POST) 。 问题是, $_POST接受被rated字符串”Array” ,而不是我定义的实际数组。 如何更正此代码,以便PHP将JSON输入识别为正确的数组,而不是字符串? var rated = {“key” : key , “value” : value}; $.ajax({ type: “POST”, url: $(location).attr(‘protocol’) + “//” + $(location).attr(‘hostname’) + “/ajax/rate.php”, data: { “rated” : rated }, success: function(data) { alert(data); } }); 这是我得到的输出消息: 数组([rating] =>数组) 致命错误 :只有变量可以通过引用传递到第X行的… / ajax / rate.php中 编辑:实际上有更多的变量被rated ,但它们都不是数组(因此它们没有问题),所以为了简洁起见,我将它们从上面的代码中删除了。

当我尝试在.each函数之外使用它时,变量变为Nan

我从外部源抓取一个JSON obj。 看起来如此: {“total”:16231642,”totalamount”:437442282.55} 我将它设置为全局var,在每个函数中设置它,然后尝试在它之外检索它,如下所示。 但我得到了一个N​​an作为价值。 该值在函数中设置为绝对,因此我不完全确定为什么会发生这种情况。 任何帮助表示赞赏! $( document ).ready(function() { var todaystart; //Get vals from JSON txt $.getJSON( “proxy.php”, function( data ) { $.each(data, function (key, val) { if (key == ‘totalamount’) { var todaystart = val; //was using parseFloat before to ensure that the datatype was correct, in case anybody answers that. […]

JqG​​rid无法显示数据

我试图从弹簧控制器显示JqGrid中的数据。 这是来自我的spring控制器的JSON响应{“rows”:[{“firstName”:”sharma”,”lastName”:”sharma”,”id”:2}],”page”:”1″,”records”:”1″,”total”:”1″} 这是我的jsp文件: $(“#grid”).jqGrid({ url:’/url’, colModel:[ {name:’id’, label: ‘ID’, formatter:’integer’, width: 40}, {name:’firstName’, label: ‘First name’, width: 300}, {name:’lastName’, label: ‘Last Name’, width: 200} ], caption: “ReportingEmployees”, pager : ‘#pager’, height: ‘auto’ }).navGrid(‘#pager’, {edit:false,add:false,del:false, search: false}); 我花了几个小时来弄清楚出了什么问题,JSON看起来也很有效。 任何帮助深表感谢。

解析JSON Ajax响应

我在解析JSON响应时遇到了麻烦。 我已经做了很多次,但这是因为我无法辨别的原因。 这是我正在做的事情: 在任何人建议之前 – 由于我正在研究的项目的一些要求,我必须使用服务器端的Google Geocoding Web服务,我无法在客户端做到这一点。 我正在使用PHP作为服务器端部分。 我正在使用AJAX(通过jQuery)将位置发送到服务器,获取响应并将其编码为JSON。 这是服务器端代码: 这是客户端调用,其中theLocation是位置名称: var postdata = “theLocation=” + encodeURIComponent(theLocation); $.ajax( { type : “POST”, url : “GeoEncode.php”, data :postdata , dataType : “JSON”, success : function(data) { data = $.parseJSON(data); lat = data.results[0].geometry.location.lat; lng = data.results[0].geometry.location.lng; }, error: function (request, status, error) { log(“Error: getLatLong Status […]

jquery ajax方法返回null值

我有一个像这样的ajax函数: $.ajax({ type: “POST”, url: ‘AjaxControls.aspx/CreateUserLevel’, data: { LevelNameAddLevel: $(‘#LevelNameAddLevel’).val() }, dataType: “json”, success: function (response) { console.log(response); if (response == “true”) { $(“#ErrorDivAddLevel”).html(‘Level created successfully!’).fadeIn(‘slow’); } else { $(“#SuccessDivAddLevel”).html(‘Level creation failed!’).fadeIn(‘slow’); } } }); 问题是响应返回null值。 网络方法是: Public Shared Function CreateUserLevel() As String Return “true” End Function

有没有办法从服务器检索JSON文件

参考我上面的问题,我想要检索文件的原因是我想知道它是如何构造的,所以我可以使用我的数据来复制我复制的脚本。 目前, $.getJSONurl包含字符串”callback=?” 在里面。 无论如何,我可以查看或查看数据是如何在$.getJSON url字符串中的文件中$.getJSON ? 实际上,我跟随下面的演示 https://code.google.com/r/kgraham-flr-map/source/browse/examples/medicare-dynamic-ds.js?spec=svn72fd5de93cf24b0b2baa5d2678d9518741e3d80b&r=72fd5de93cf24b0b2baa5d2678d9518741e3d80b 有问题的脚本有$.getJSON(‘https://storelocator-go-demo.appspot.com/query?callback=?’来解析数据。 当我尝试打开url时,我收到此错误strconv.ParseFloat: parsing “”: invalid syntax 我想看看JSON文件是如何构造的,所以我可以用我自己的数据替换它。 希望这能解决我的问题。

ASP.NET MVC – JSON响应向我发送文件而不是更新jqueryUI

我正在返回一个json数据,我可以确认它正在将数据带回客户端。 但它没有更新我的jqueryaccordion,而是要求我保存或打开文件。 下面是我的脚本和控制器。 我使用jquery模式对话框通过部分视图编辑员工详细信息,点击更新按钮应该更新手风琴列表中的相应员工。非常感谢任何帮助 – 谢谢 更新 通过IE工具进行调试时,我注意到单击“更新”按钮时,“请求”选项卡中的“启动器”显示“单击”。 我猜这应该是’XMLHttpRequest’而是。 希望这些信息有所帮助 谢谢 主视图 @Html.ActionLink(“Edit Employee”, “EditEmployees”, “Home”, new { id = item.Id } , new { @class = “editLink” }) 带编辑员工表单的部分视图 – EditEmployee.cshtml @using (Ajax.BeginForm(“EditEmployees”, “Home”, new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = “POST”, OnSuccess = “updateSuccess” }, new { @id = “updateEmployeeForm” })) { […]

使用Google Maps API从JSON文件显示多边形

我能够将JSON文件加载到页面中(当前使用jQuery),并将内容设置为页面中的变量。 JSON包括对构建轮廓的引用,如下所示; [ { “buildingNumber”:”7″, “buildingDescription”:”Building Seven”, “spatial”:{ “points”: [ “-1.2345678,50.9876543”, “-1.2345677,50.9876544”, “-1.2345676,50.9876545”, “-1.2345675,50.9876546” ] } } ] 使用jQuery的$.each ,我可以加载变量并遍历建筑物,另外,每个建筑物,我可以非常简单地遍历这些点。 问题在于,Google似乎只记录了以下用于描述多边形的方法; var triangleCoords = [ new google.maps.LatLng(25.774252, -80.190262), new google.maps.LatLng(18.466465, -66.118292), new google.maps.LatLng(32.321384, -64.75737) ]; 这是有道理的,但我看不出如何从我目前拥有的数组到这种格式。 我真的很感激任何关于从一个移动到另一个的起点的指针,或者描述多边形的另一种方式。 我已经查看了array.push()函数,虽然看起来像是本地的方法,但我看不出如何根据数组中的迭代值动态创建变量。 谢谢

getJSON没有返回任何内容

下面的JSON函数没有返回任何内容…… $.getJSON(formUrl, function(data) { alert(data) $(‘.response’).html(” + data.title + ” + ” + data.description + ”); }); formUrl是正确的并以forms返回数据 {“title”:”Smashing Magazine”,”description”:”Smashing Magazine is focused on design and web-development. We deliver useful information, latest trends and techniques, useful ideas, innovative approaches and tools.”} 谁能指出我做错了什么? 我正在提醒数据及其空白…… 谢谢!

JSON不能使用JQuery

我的JSON有问题吗? http://codepen.io/anon/pen/Ieyvl var url = “http://x.com/json.js”; $.getJSON(url, function(response){ alert(“worked!”); alert(response); }); 如果它是一个“跨域”问题,那么为什么这样做呢? http://codepen.io/anon/pen/BHshC var url = “http://gdata.youtube.com/feeds/api/playlists/PL3E245DF445E37F50?v=2&alt=jsonc”; $.getJSON(url, function(response){ alert(“worked!”); alert(response); });