
PHP $_POST提交表单乱码解决方法是在代码头部加入“echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';”即可解决提交数据乱码问题。
问题详情:
在提交页面 设置头<meta charset="UTF-8">
,并确保编辑器保存的也是utf-8
显示页面也加上html
头部。
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
解决方案:
前端调用接口,后端接收数据保存数据库,注意contentType
一定这样设置:
if(isSuccess){ var token = sessionStorage.token; $.ajax({ type:'post', url:'../../api/container/' token '/addContainerDamageReport', contentType:'application/x-www-form-urlencoded;charset=utf-8', data:{'containerName':'HJSY' containerName,'username':username,'description':descript,'damageTime':damageTime ,'reportTime':reportTime,'damageLevel':badLevel,'damageType':badType}, cache:false, dataType:'json', success:function(data){ $('#submit').attr('data-dismiss',"modal"); console.log(data) } }) }
后端接受:页面的编码格式utf-8,SQL server数据库是gbk,注意转换,否则插入进去是乱码。
更多学习教程:PHP的HTTP协议视频教程
更多关于云服务器,域名注册,虚拟主机的问题,请访问西部数码官网:www.west.cn