1. 返回结果差异
JS 获取后打印 res.code 无结果. 因为返回数据格式不正确.
PHP 文件添加 header 头:
header('Content-Type:application/json;');
或者. j s 添加
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- $.Ajax({
- url:'../data/insert_category.php?article_type=' + value,
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success:function(res){
- console.log('异步成功');
- console.log(res);
- console.log(res.code);
- },
- error:function(){
- console.log('异步失败');
- }
- })
总结
来源: https://www.jb51.net/article/150487.htm