当前位置:网站首页>从控制层返回到js的json数据带“\”转译符,怎么去掉
从控制层返回到js的json数据带“\”转译符,怎么去掉
2022-06-30 14:10:00 【全栈程序员站长】
场景:写了一个ajax,调用url后,从控制层返回的数据是json格式。
ajax的内容是,里面注释有说明:
$.ajax({
url : '${base}/commonDialog/applyCis5ZZCAntiReport?appNo=${(appNo)!}'+'&loanType='+loanType+
'&loanAmount='+loanAmount+'&loanPurpose='+loanPurpose+'&loanTerm='+loanTerm+
'&custName='+custName+'&mobile='+mobile+'&idNo='+idNo,
type : "post",
success:function(res){<#--url调用结束后,返回的数据在res中-->
$("#result").empty();<#--result是一个div的id。可不用考虑-->
var json="";
json=JSON.stringify(res,null, 4);<#--这里小编也不懂啥意思,应该是json转var格式吧!-->
$("#result").append(json);<#--把返回的结果追加到div中,此时追加的内容就是满屏的转译符"\">
}
})
});百度了很多办法,都没有解决,最多的就是使用replacet替换,最接近预想结果的是在上面的success方法中,加上:
var json=res.replace("\\","");
$("#result").append(json);这个方法确实是去掉不少转译符”\”.但是在遇到层级比较复杂的json字符串,就难免有漏网之鱼,因为毕竟不是从造成此种情况的根本原因着手解决的。
js是支持json格式的,从后台到前端如果没有指定数据格式,应该会默认是字符串的,把json格式数据/toString()打印到控制台是带有”\”的。因此只要在ajax中指定返回数据的格式就行了!加上“dataType:json”即可。
type:"post"
dataType:"json",发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/106262.html原文链接:https://javaforall.cn
边栏推荐
猜你喜欢

【观察】智能产业加速,为何AI算力要先行?

Waving flags and shouting for basic language

Optimization of unit test efficiency: why test programs? What are the benefits of testing?
![[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure](/img/5a/5da6180db0b2b96660bcd9b4fa0633.png)
[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure
![[Title brushing] heater](/img/ee/70e122b1b1a406624aa7c6442fcdc1.png)
[Title brushing] heater

Jetpack Compose 实现完美屏幕适配

There is no utf8 option for creating tables in Navicat database.

深入理解.Net中的线程同步之构造模式(二)内核模式4.内核模式构造物的总结

Wuenda 2022 machine learning special course evaluation is coming!
![【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)](/img/5a/eaa845f4332f0b8ee8b6409d6a79e8.png)
【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
随机推荐
编程实战赛来啦!B站周边、高级会员等好礼送你啦!
Three uses of golang underscores
Introduction to the renewal of substrate source code: the pallet alliance is incorporated into the main line,
【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
Simple understanding of the difference between get request and post submission
Multi terminal collaboration of Huawei accounts to create a better internet life
[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure
深入理解.Net中的线程同步之构造模式(二)内核模式2.内核模式构造物Semaphone
Deep understanding Net (2) kernel mode 4 Summary of kernel pattern constructs
Dart extended feature
Calculates the length of the last word in a string, separated by spaces
MFQE 2.0: A New Approach for Multi-FrameQuality Enhancement on Compressed Video
Deep understanding Net (2) kernel mode 3 Kernel mode construct mutex
(8) JMeter component detailed once only controller
Implementation of forwarding server using IO multiplexing
Yousi College: Six Sigma is not just statistics!
Dart 扩展特性
DNS resolution home network access public DNS practice
[kubernetes series] k8s set mysql8 case insensitive
Meaning of while (~scanf ("%d%d", & A, & B))