我使用springmvc和tinymce编辑器。我想通过ajax发送编辑器的内容作为参数。此内容可能有特殊字符。如果它有特殊的字符内容被破坏。 1)为什么有特殊字符的内容不能完全发送? (special char : %,>,
$(document).ready(function() {
$("#addStep").click(function(){
var content = tinyMCE.get("content");
var dataString = 'content='+ content.getContent();
$.ajax({
type: "post",
url: "addStep.htm",
data: dataString,
cache: false,
成功:功能(响应) {
if(response.status == "SUCCESS"){
//--------------
}
});
});
和我的控制器
@RequestMapping(value="/addStep.htm",method=RequestMethod.POST)
public @ResponseBody JsonResponse addStep(@ModelAttribute(value="answer") Answer answer,BindingResult result,HttpSession session,HttpServletRequest request,ModelMap model,@ModelAttribute("stepList") List stepList){
JsonResponse res = new JsonResponse();
ValidationUtils.rejectIfEmpty(result, "content", "h");
if(!result.hasErrors()){
stepList.add(answer);
res.setStatus("SUCCESS");
res.setResult(stepList);
}else{
res.setStatus("FAIL");
res.setResult(result.getAllErrors());
}
return res;
}
2014-10-31
Hadi J
+0
你得到哪个错误? –
2014-10-31 13:08:18
+1
使用'encodeURIComponent(queryString)'而不是'queryString'。但你的网址是简单的字母表。特殊字符在哪里? –
2014-10-31 13:09:43
+0
我编辑了我的问题。我的错误是:java.io.charconversionexception ishexdigit –
2014-10-31 13:13:09
在使用SpringMVC和TinyMCE编辑器的项目中,遇到一个问题:当尝试通过Ajax发送包含特殊字符的内容时,内容会遭到破坏。错误提示为'java.io.CharConversionException ishexdigit'。问题可能源于特殊字符未正确编码。解决方案可能是使用encodeURIComponent对查询字符串进行编码。在Ajax请求中,将内容编码为dataString='content=' + encodeURIComponent(content.getContent()),这可以确保特殊字符正确传递给服务器。
1644

被折叠的 条评论
为什么被折叠?



