Tag: json

Scala操作没有执行将json对象存储在ajax上使用Play Framework和Scala提交到Postgresql数据库?

我在我的视图页面(index.coffee)中有一个json对象,我在发送到Scala控制器类以通过jQuery / ajax存储在Postgresql数据库中,然后单击我的提交按钮。 我已经完成了以下操作:(控制器,模型和数据库表),但是在单击Submit按钮后我没有在数据库表中看到任何json数据,即使我在控制台上看不到任何错误和我的println()消息(我希望addJson ()动作没有执行)。我不确定我在所有文件的整个代码中做错了什么和哪里错了? 当我的Play Framework服务器(2.2.3)连接到我的数据库时(我可以看到控制台上的消息说:[info] play – database [default] connect at:jdbc:postgresql:// localhost:5432 / mydb)请让我知道我做错了什么,并提前感谢。 app.scala: package controllers import play.api.mvc._ import play.libs.Json; import com.fasterxml.jackson.databind.JsonNode; import play.api._ import play.api.mvc.Request import play.api.libs.json._ import play.api.mvc.AnyContent; import play.libs.Json; import com.fasterxml.jackson.databind.JsonNode; import anorm._ import play.api.data.Form import play.api.data.Forms.{single, nonEmptyText} import play.api.data._ import play.api.data.Forms._ import play.api.mvc.{Action, Controller} import anorm.NotAssigned import models.Jsoncontent […]

wikimedia api从json字符串获取相关数据

这是我昨天问的问题 。 我能够获得所需的数据。 最终数据是这样的。 请点击此链接 。 我尝试使用以下代码来获取所有信息框数据 content = content.split(“}}\n”); for(k in content) { if(content[k].search(“Infobox”)==2) { var infobox = content[k]; alert(infobox); infobox = infobox.replace(“{{“,””); alert(infobox); infobox = infobox.split(“\n|”); //alert(infobox[0]); var infohtml=””; for(l in infobox) { if(infobox[l].search(“=”)>0) { var line = infobox[l].split(“=”); infohtml = infohtml+””+line[0]+””+line[1]+””; } } infohtml=””+infohtml+””; $(‘#con’).html(infohtml); break; } } 我最初认为每个元素都包含在{{}}中。 所以我写了这段代码。 但我所看到的是,我无法通过此获取整个信息框数据。 有这个元素 […]

使用JSON的Colorbox库

一直在玩这个 尝试使用Colorbox加载图像库,其中URL通过JSON调用加载,而不在主页上显示图像 在http://www.jacklmoore.com/demo/flickr.html浏览了flickr的示例 我已经尝试了很多路由,我已经将代码半工作了 var links = $() ,link ,img ; $.getJSON(‘http://URL/json.json’, function(data) { $.each(data, function(index, photo) { link = $(”, { href: photo.url ,title: photo.name }); img = $(”).attr({ src: photo.url ,alt: photo.name }).appendTo(link); links = links.add(link); }); $(‘#gallery-holder’).html(links); }); $.colorbox({ rel: ‘gallery’ ,inline: true ,href: ‘#gallery-holder’ }); /* $.colorbox({ html:links ,rel: ‘gallery’ ,inline: […]

Jquery从PHP接收json消息

我有以下提交到iframe的jquery函数。 从PHP发回的消息是json。 我无法弄清楚如何在jquery中收到此消息,以便我可以将其显示给用户。 function IframeSubmit(){ // remove iframe if exists $(‘#hiddenIframe’).remove(); // change target attribute on form form.attr(‘target’, ‘hiddenIframe’); // create and add iframe to page $(”, { name: ‘hiddenIframe’, id: ‘hiddenIframe’, style: ‘display:none’ }).appendTo(‘body’); // on response from php file $(‘#hiddenIframe’).load(function(){ // process received message here … }); } 谢谢!

仅在firefox中出现JSON语法错误

我在使用$.parseJSON()时在FireFox中遇到语法错误。 相同的代码在Chrome / Chromium和Safari上正常运行。 我调用此函数来获取随机生成的令牌。 function getToken() { var url = “/csrf_token_generate”; $.ajax({ url: url, method: “GET” }).done(function(data) { console.log(data); // Logs the data from the call var json = $.parseJSON(data); // Where the error occurs token = json.token; console.log(token); }); } URL /csrf_token_genrate返回类似于{“token”:”$2y$10$jcr.P3FNqeji6RqD93LnxeIKs9gYNiPj7cboahz8RCCSgKw7VOfhi”}的JSON对象{“token”:”$2y$10$jcr.P3FNqeji6RqD93LnxeIKs9gYNiPj7cboahz8RCCSgKw7VOfhi”} 在URL中,我将Content-Type设置为application/json ,它适用于所有其他浏览器。 我得到的错误就是这个 SyntaxError: JSON.parse: unexpected character at line 1 column […]

如何让jQuery Fancybox接受我的对象作为有效的开放参数?

我有一些这种格式的HTML: First Logo Second Logo Third Logo 我想逐步完成并将它提供给像这样的 Fancybox。 我已经达到了这个目标,但它直接起作用了: downloadList = $(‘#logos ul li a’); var downloadArray = {}; downloadJSON = ”; $.each(downloadList, function(d) { var download = $(this); var href = download.data(‘image’); var title = download[0].innerText; var link = download[0].href; downloadArray[d] = {}; downloadArray[d].href = href; downloadArray[d].title = “”+title+””; downloadJSON += JSON.stringify(downloadArray[d])+’,’; }); […]

解析标签的json数据以突出显示字段中的文本

{ “responseHeader”: { “status”: 0, “QTime”: 32 }, “response”: { “numFound”: 21, “start”: 0, “docs”: [ { “description”: “The matte finish waves on this wedding band contrast with the high polish borders. This sharp and elegant design was finely crafted in Japan.”, “UID_PK”: “8252”, }, { “description”: “This elegant ring has an Akoya cultured pearl […]

JSON如何从Javascript对象中的值中找到同一索引处的另一个值

一个简单的问题我敢肯定,但我无法弄清楚。 我从服务器返回了一些JSON while ($Row = mysql_fetch_array($params)) { $jsondata[]= array(‘adc’=>$Row[“adc”], ‘adSNU’=>$Row[“adSNU”], ‘adname’=>$Row[“adname”], ‘adcl’=>$Row[“adcl”], ‘adt’=>$Row[“adt”]); }; echo json_encode(array(“Ships” => $jsondata)); …我在ajax调用中在客户端使用。 应该注意的是,JSON被解析为一个全局声明的对象,以便以后可用,并且我假设你知道我正确地形成了ajax调用… if (ajaxRequest.readyState==4 && ajaxRequest.status==200 || ajaxRequest.status==0) { WShipsObject = JSON.parse(ajaxRequest.responseText); var eeWShips = document.getElementById(“eeWShipsContainer”); for (i=0;i<WShipsObject.Ships.length;i++) { newElement = WShipsObject.Ships; newWShip = document.createElement("div"); newWShip.id = newElement[i].adSNU; newWShip.class = newElement[i].adc; eeWShips.appendChild(newWShip); } // end for }// […]

如何在AJAX中处理JSON输出?

我在.js文件中有这段代码片段 $(function () { // KeyDates var url = “http://localhost:8732/Design_Time_Addresses/Intel.IIP.MDF.WCF/ProgramCalendarService/GetKeyDatesCalendarNew”; $.ajax({ url: url, data: null, type: ‘POST’, contentType: ‘application/json’, dataType: ‘json’, success: function (GetKeyDatesCalendarDataNew) { alert(GetKeyDatesCalendarDataNew); $(document).ajaxStop($.unblockUI); } }); }); 如何处理GetKeyDatesCalendarDataNew中的键值对?

将值推入嵌套的ko.observableArray

我希望将供应商列表嵌入到我从服务器获得的现有JSON Payload中,具体取决于JSON Payload中的项是否需要供应商。 我最终想要的是这样的事情: { “ProductName”: “Product123”, “RequiredComponents”: “CAP 10% H/Vol”, “StockCode”: “142111411”, “RequiredQtyByBom”: 4, “QtyUnassignedInWarehouse”: 0, “QtyAllocatedInWarehouse”: 40, “PCBReference”: “442C”, “QtyOnOrder”: 26, “Vendors”: [], “RequireVendor”: false }, { “ProductName”: “Product123”, “RequiredComponents”: “Screws”, “StockCode”: “Screws”, “RequiredQtyByBom”: 1, “QtyUnassignedInWarehouse”: 0, “QtyAllocatedInWarehouse”: 14, “PCBReference”: “Screws”, “QtyOnOrder”: 26, “Vendors”: [ {“VendorID”: “3”, “VendorName”: “ABC Supplier”, “VendorMOQ”: 50000, “VendorItemPrice”: […]