今天,我使用Axios写注册的AJAX提交JS,它可以正常的发送请求,但我发现后端完全无法正常接受前端传来的username和password信息,我应该如何修复这个BUG?谢谢。部分JS代码(jQuery):varcaptcha_res_ticket=$.cookie("captcha.res.ticket");varcaptcha_res_randstr=$.cookie("captcha.res.randstr");varusername=$("#inputUsername").val();varemail=$("#inputEmail").val();varpassword=$("#inputPassword").val();varrepassword=$("#inputRepassword").val();varagree_user_agreement=$("#agree_user_agreement").is(":checked");varparticipate_in_the_user_experience_program=$("#participate_in_the_user_experience_program").is(":checked");Axios部分代码:axios({url:'/user/user_registration/php/registration.php',method:'post',timeout:3000,data:{captcha_res_ticket:captcha_res_ticket,captcha_res_randstr:captcha_res_randstr,username:username,email:email,password:password}})Captcha来自我的验证码API。
2 回答

慕盖茨4494581
TA贡献1850条经验 获得超11个赞
Axios部分代码(JS):constparams=newURLSearchParams();params.append('captcha_res_ticket',captcha_res_ticket);params.append('captcha_res_randstr',captcha_res_randstr);params.append('username',username);params.append('password',password);axios({url:'/user/user_login/php/login.php',method:'post',timeout:1000,data:params})

慕尼黑8549860
TA贡献1818条经验 获得超11个赞
超全局变量$_POST无法接受content-type:application/json的请求body。解决方案echofile_get_contents('php://input');
添加回答
举报
0/150
提交
取消