在调试bug时,ajax提交的参数是一段html标签:
var content="<img src='www.xxx.com/image/xxxx.jpg' alt='' />"
$.ajax({
url: "/xxxx/xxxx?method=sendPic",
data:{"content":content},
dataType: "json",
type: "post",
success: function(result) {
}
});
然后在后台接收时,获取到的参数是:
content="<img src='' alt='' />"
在前端的日志中显示src是有值的,一到后端的时候突然就为空值了,在网上查阅资料也没有查出具体原因,只找到了相关的解决方法:解决ajax提交内容包含<img>标签,无法获取到src值的方法 。在前端先将要传递的img标签中的src进行修改,改成src1,然后通过ajax提交
content=content.replace(/src/g,"src1");
$.ajax({
url: "/xxxx/xxxx?method=sendPic",
data:{"content":content},
dataType: "json",
type: "post",
success: function(result) {
}
});
然后在后端获取到参数后,在把src1转为src即可。
content=content.replaceAll("src1", "src");
如果知道问题的原因,请留言告说明一下,十分感谢。