ajax 是一个不错的东西
当 dataType:'json'时提交,总是返回 error
这是为什么?
经过折腾,终于发现因为要求的是 json,返回的信息并不是 json 格式,因此总是出错
因为...
我竟然在文件里引用了 html 文件,然后再输出...
这里再附上 php 生成 json 的坑...
$color = array('red','blue','green'); //【索引数组】
echo json_encode($color),"<br />"; //["red","blue","green"]
$animal = array('east'=>'tiger','north'=>'wolf','south'=>'monkey'); //【关联数组】
echo json_encode($animal),"<br />";//{"east":"tiger","north":"wolf","south":"monkey"}
$animal2 = array('east'=>'tiger','north'=>'wolf','duck','south'=>'monkey');//【索引关联数组】
echo json_encode($animal2),"<br />";//{"east":"tiger","north":"wolf","0":"duck","south":"monkey"}
总结:当只是索引的时候,是不会生成 json 的!!! 而带了键值,才能。。 再看混合类型,索引的直接带上 0,因为有键值在,要生成空间留着
json_encode(数组/对象)------------>生成 json 信息,
json_decode(json 信息); 反编码 json 信息
终于,染念在此时解决了 bug - -
2020/3/14 增加:

再加一层数字伪装索引失败,因为--
$a=[1,2,3,4,5,6];
本身就是
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)
