我正在尝试使用JSON将数组发布到PHP文件。这没用。问题是什么也没发生。如果我将数据类型分解为:“ json”,则会收到警报(但没有数据)。
这是我的jQuery代码
var arr = new Array();
arr.push('1','Brussels|25');
arr.push('2','Antwerp|40');
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "jsondecode.php",
data: JSON.stringify(arr),
dataType: "json",
success: function(data){alert(data);},
failure: function(errMsg) {
alert(errMsg);
}
});
这是我的PHP代码(jsondecode.php);
<?php
$array = json_decode($_POST["arr"]);
foreach($array as $el){
$el_array=explode('|',$el);
echo"City=".$el_array[0]." And Age = ".$el_array[1]."";
}
?>
有人知道这方面有用的教程吗?
php大神给出的解决方案
您必须以这种格式发布数据才能像$_POST["arr"]
一样进行检索
data: { arr : JSON.stringify(arr) },
post_save信号未调用 - python我已经阅读了所有相关问题。我有两个Django项目,信号在一个项目中可以正常工作,但在第二个项目中却不能工作(我只是复制粘贴代码并分别更改了名称)。我有一个带有订单模型的订单应用。应用程序包含在INSTALLED_APPS设置中。我在apps.py中有应用程序配置:from django.apps import AppConfig class OrdersC…
jQuery-根据用户输入显示/隐藏 - php我的页面上有以下div:<div id="page1"> Some content </div> <div id="page2"> More content </div> <div id="page3"> Even more content…
为什么我的注册表单可以在除Firefox之外的所有浏览器中使用? - php在这里可用:http://syllableapp.com/test基本上,在Safari,Chrome,Opera,Webkit Nightly等中,表单可以完美地按预期工作。但是,在Firefox中,提交时只是...不执行任何操作。为什么是这样?这是我的JavaScript:$(document).ready(function() { $('in…
LeetCode题解365.water-and-jug-problem题目地址 https://leetcode.com/problems/water-and-jug-problem/description/ 题目描述 You are given two jugs with capacities x and y litres. There is an infinite amount of water supply availa…
LeetCode题解201.bitwise-and-of-numbers-range题目地址 https://leetcode.com/problems/bitwise-and-of-numbers-range/description/ 题目描述 Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbe…