ajax异步请求返回的是字符串问题

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('异步失败');
            	}
            })

猜你喜欢

转载自blog.csdn.net/milli236/article/details/83897412
今日推荐