为了账号安全,请及时绑定邮箱和手机立即绑定

ajax xhr.responseText 当结果包含@error uncaught

ajax xhr.responseText 当结果包含@error uncaught

慕尼黑5688855 2022-12-09 13:46:41
我通过 new XMLHttpRequest() 进行 ajax 调用;当我这样做时var params = "x="+encodeURIComponent(x);var xhr = new XMLHttpRequest(); xhr.open("POST", "....php", true);xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");xhr.onreadystatechange = function(e) {    if (xhr.readyState == 4) {        $("#divID").html(e.currentTarget.responseText);    }}xhr.send(params);它很好并且运行良好.....但是当结果包含@时我在控制台日志中收到此错误Uncaught TypeError: Cannot read property 'removeChild' of null without using removeChild澄清:例如:当 php 给出<img src="..." />-->> 没关系当 php 给出some text blablabla ...blalbla contact allo@test.com-->> 我得到错误为什么我需要修复它???
查看完整描述

2 回答

?
慕姐8265434

TA贡献1813条经验 获得超2个赞

与在 ajax 中一样,您发送的是纯 html 代码。我建议你在 ajax 响应中使用 json 格式。这将解决你的问题



查看完整回答
反对 回复 2022-12-09
?
明月笑刀无情

TA贡献1828条经验 获得超4个赞

我找到了一个“可行”的解决方案


在 ajax 调用的 php 中,我只执行一个回显并将任何出现的 @ 替换为 &commat


$stuff = ...; // gathering what to echo

$stuff .= ...; // gathering what to echo

$stuff = str_replace('@','&commat;',$stuff); 

echo $stuff;

这样浏览器显示@并且错误不会出现在控制台日志中


注意:我尝试在 javascript 级别 (e.currentTarget.responseText) 中进行替换,但没有成功。


查看完整回答
反对 回复 2022-12-09
  • 2 回答
  • 0 关注
  • 100 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号