Tag: json

如何将JSON代码导入MYSQL数据库?

我用jQuery自动完成function创建了这个表单。 自动完成列表中的所选品牌需要使用$ .ajax函数发送到PHP文件。 我的代码似乎不起作用,但我找不到错误。 我不知道为什么数据没有插入到MYSQL数据库中。 这是我的代码: JQUERY: $(document).ready(function() { $(“#autocomplete”).autocomplete({ minLength: 2 }); $(“#autocomplete”).autocomplete({ source: [“Adidas”, “Airforce”, “Alpha Industries”, “Asics”, “Bikkemberg”, “Birkenstock”, “Bjorn Borg”, “Brunotti”, “Calvin Klein”, “Cars Jeans”, “Chanel”, “Chasin”, “Diesel”, “Dior”, “DKNY”, “Dolce & Gabbana”] }); $(“#add-brand”).click(function() { var merk = $(“#autocomplete”).val(); $(“#selected-brands”).append(” ” + merk + “”); //Add your parameters here var […]

使用Javascript进行基本授权API登录(CORS?)

我已经阅读了许多关于尝试使用Javascript使用基本授权登录网站的API的线索,我觉得我已经尝试了所有我已经看过的建议,但我无法让它工作。 我有一种感觉,这可能是一个双重问题,因为我收到401错误,还有一个No Access-Control-Allow-Origin错误。 有人可以向我解释我做错了什么吗? 我尝试过几种不同的授权方式,但结果总是一样。 我可以通过Python和Postman使用基本授权连接到相同的API,所以不确定为什么Javascript对我不起作用。 对我来说很容易,我是Javascript的新手! 这是我的脚本: function logIn() { var userName = document.getElementById(“username”).value; var pWord = document.getElementById(“password”).value; console.log(“Your username is: ” + userName); $.ajax ({ type: “GET”, url: “https://example.com”, dataType: ‘json’, async: false, headers: { “Authorization”: “Basic ” + btoa(userName + “:” + pWord) }, success: function (){ alert(‘Thanks for logging in!’); } […]

php的数据表和json格式错误

我对dataTables和php有点困难。 我以下面的格式回应json: {“iTotalRecords”:10,“iTotalDisplayRecords”:10,“aaData”:[[“1”,“15”,“1”,“长描述长描述长描述”,“2012-02-25 00: 00:00“],[”1“,”15“,”1“,”长描述长描述长描述“,”2012-02-25 00:18:59“] …]} 哪个inst使用我的dataTable,但是在jsonlint.com/中validation了上面的内容后,我得到了以下格式良好的版本: { “iTotalRecords”: 10, “iTotalDisplayRecords”: 10, “aaData”: [ [ “1”, “15”, “1”, “long description long description long description long description”, “2012-02-25 00:18:59” ], … ] } 当我把它放在一个txt文件中时,它加载得很好。 我还注意到在“长描述”部分添加换行符,即使使用上面的那个也不行。 我的猜测是,换行符是json格式的混乱,但是我怎么能在我的PHP脚本中避免这种情况,因为所有内容都是自动换行的? 我在我的echo代码中尝试了\ n但它似乎没有创建换行符。

发出访问json对象值的问题

我有一个问题console.logging从我的jquery ajax调用发送回脚本的json对象的值。 剧本: for(i=0; i<IDs.length; i++) { var vendor = IDs[i]; $j.ajax({ type: "POST", url: "/ajax_calls/updatePrices.php", data: { 'vendorID': vendor, 'product_id': product_id} }).done(function(data) { console.log('The data is ' + data); var basePrice = simpleArray[vendor][colorSelected]; //if(data.tier2_range_start[i]) console.log('Range start is data.tier2_range_start: ' + data.tier2_range_start); if (qty data.tier2_range_start){ simpleArray[vendor][colorSelected]= (basePrice * qty) * data.tier2_discount; } else if (qty […]

如何让JSONP与jQuery一起使用?

我试图从Flickr API获取一些JSONP来使用: http://jsfiddle.net/SRc98/ $.getScript(‘http://api.flickr.com/services/feeds/photos_public.gne?format=json&tags=cats’, function(data, textStatus, jqxhr) { alert(data); }); 警报提供undefined ,控制台说: Uncaught ReferenceError: jsonFlickrFeed is not defined Flickr API响应有什么问题,或者有没有办法让它工作? http://api.flickr.com/services/feeds/photos_public.gne?format=json&tags=cats

数组在JSON请求之外消失

我正在尝试使用YouTubevideo的各种属性设置一个数组(您可能认为这有点多余,但我计划将来添加其他来源)。 我可以在JSON请求中将这些值添加到数组中,但是一旦我离开它,它们就会消失。 有任何想法吗? var socialPosts = new Array(); $.getJSON(‘https://gdata.youtube.com/feeds/api/videos?author=google&max-results=5&v=2&alt=jsonc&orderby=published’, function(data) { for(var i=0; i<data.data.items.length; i++) { //for each YouTube video in the request socialPosts[i]={date:Date.parse(data.data.items[i].uploaded), title:data.data.items[i].title,source:"YouTube", thumbnail:data.data.items[i].thumbnail.hqDefault, url:'http://www.youtube.com/watch?v=' + data.data.items[i].id}; //Add values of YouTube video to array } console.log(socialPosts[0].date); //This returns the correct data }); console.log(socialPosts[0].date); //This returns with undefined

使用Ajax将JSON发送到ASP.NET Web方法

这是我第一次尝试使用Ajax将数据发送到服务器。 我从这里”Message”:”Invalid web service call, missing value for parameter: \u0027Products\u0027.”很多答案,但我不会停止收到错误: “Message”:”Invalid web service call, missing value for parameter: \u0027Products\u0027.” 我跟着这个 ,但仍然是一样的。 有人可以告诉我哪里出错了。 var products = [ { ProductId : 1, ProductName : “Mercedes”, Category : “Cars”, Price : 25000 }, { ProductId : 2, ProductName : “Otobi”, Category : “Furniture”, Price : 20000 } ]; […]

JSON没有在模态窗口上停止表单提交

我有一个mvc项目。 我在modal dialog中打开一个表单。 用户填写表格并点击保存。 表单发布到控制器,但我试图拦截并通过json发布。 查看开发工具网络部分以及在我的json中有alert()它没有运行,我认为它没有正确附加? 我已阅读了几页,看来我的json基本上是正确的。 我知道父页面和窗口之间存在关系…这是一个成为模态窗口的div。 但是,我不知道这是否属于分解的一部分。 在父窗口中,这是我的模态的启动方式。 $(“#edit”).click(function (e) { e.preventDefault(); var detailsWindow = $(“#window”).data(“kendoWindow”); if (!detailsWindow) { // create a new window, if there is none on the page detailsWindow = $(“#window”) // set its content to ‘loading…’ until the partial is loaded .html(“Loading…”) .kendoWindow( { modal: true, width: “800px”, height: […]

使用JQuery UI自动完成function从JSON搜索数据无法正常工作

如何使用获取的json数据使用JQuery UI自动完成? 它不适用于我的。 我使用这个例子http://jqueryui.com/autocomplete/ ,而不是我从json获取的硬编码数据。 我的json数据来自url localhost/myproject/output/names 。 HTML JS $(function() { $( “#search” ).autocomplete({ source: “localhost/myproject/output/names” }); }); json数据 [{“fullname”:”John Smith”},{“fullname”:”Juan dela Cruz”}] 编辑 我已经设法用@artm评论json数据来解决这个问题。 现在是[{John Smith},{Juan dela Cruz}] 但另一个问题是,当我输入字母o ,即使只有John Smith包含o也建议使用这两个字母。 我怎样才能解决这个问题?

Json用undefined填充下拉列表

Json用undefined填充我的Drop-down。 undefined undefined undefined etc 我使用以下代码来填充我的Drop-Down; $(“select[name$=’product_type’]”).change(function(){ var url = “/all_json_models/” + $(this).val(); var product_type = $(this).val(); $.getJSON(url, function(products){ var options = ‘Select a type’; for (var i = 0; i < products.length; i++) { options += '’ + products[i].product_description + ”; } $(“select#id_orderline_set-0-product”).html(options); $(“select#id_orderline_set-0-product option:first”).attr(‘selected’, ‘selected’); $(“select#id_orderline_set-0-product”).attr(‘disabled’, false); }); }) function(产品)的内容; [{ “fields”: { […]