Struts2 将tinymice富文本编辑器内容获取到Struts操作方法中的一个问题
我已经在我的项目中集成了tinymice富文本, 当用户输入包含图像和其他丰富内容的富文本时,我通过ajax调用将内容传递给struts操作方法,然后将其发送到服务器Struts2 将tinymice富文本编辑器内容获取到Struts操作方法中的一个问题,struts2,tinymce,rich-text-editor,Struts2,Tinymce,Rich Text Editor,我已经在我的项目中集成了tinymice富文本, 当用户输入包含图像和其他丰富内容的富文本时,我通过ajax调用将内容传递给struts操作方法,然后将其发送到服务器 tinymce.activeEditor.getContent(); 上面的一行返回我的内容如下 <p>Test tinymice text content</p> <p> </p> <p>with multi line text</p>
tinymce.activeEditor.getContent();
上面的一行返回我的内容如下
<p>Test tinymice text content</p>
<p> </p>
<p>with multi line text</p>
<p> </p>
<p>And <strong>Bold text</strong></p>
<p>Test tinymice text content</p>
<p>
更新-
我的ajax代码
var postTitle = document.getElementById("title").value;
var postDescription = tinymce.activeEditor.getContent();
var formdata = "title="+postTitle+"&"+"description="+postDescription;
// call function for handling Ajax part
$.ajax({
type: "POST",
url : "postDetails" ,
contentType: "application/x-www-form-urlencoded",
async: true,
data : formdata,
cache: false,
processData: false,
datatype: json,
success: successBlock,
error: failureBlock
});
当我发出警报时,上面代码中的表单数据如下所示
title=test&description=<p>Test tinymice text content</p>
<p> </p>
<p>with multi line text</p>
<p> </p>
<p>And Bold text</p>
我已经找到了我问题的答案。 在发布数据之前,我必须使用encodeURI 更新的ajax代码
//Remove form data
//var formdata = "title="+postTitle+"&"+"description="+postDescription;
// call function for handling Ajax part
$.ajax({
type: "POST",
url : "postDetails" ,
//Remove contentType , it should not be form urlencoded
// contentType: "application/x-www-form-urlencoded",
// async: true,
//Use encodeURI to get rid of special characters within richText
data :{title:postTitle,description:encodeURI(postDescription)},
// cache: false,
// processData: false,
datatype: json,
success: successBlock,
error: failureBlock
});
您需要提供有关如何发送、对其执行的任何操作等的更多信息。如果您有错误,您可以发布错误堆栈跟踪,但如果没有源代码,它将毫无用处。@DaveNewton请检查代码given@RomanC非工作代码与主题无关!请检查网站的链接,确保正确推荐。破译的代码属于如此@那么CR是什么???对不起,那是废话。我们检查代码。CR不是一个共享代码的平台,使用github、JSFIDLE。。。而不是你提到的其他事情。此外,我的评论主要不是关于迁移。核心问题是,OP来到CR,然后被杀了,因为你没有阅读帮助中心。此外,CR知道这些帖子在CR上是作为建议迁移的自定义标志的支柱。这就是我在之前的评论中提到迁移的原因。如果你想进一步讨论这个问题,请随时询问或与我联系
public class DescriptionAction {
String title;
String description;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
//Action method
public String postDescription(){
//Here my server request goes
}
}
//Remove form data
//var formdata = "title="+postTitle+"&"+"description="+postDescription;
// call function for handling Ajax part
$.ajax({
type: "POST",
url : "postDetails" ,
//Remove contentType , it should not be form urlencoded
// contentType: "application/x-www-form-urlencoded",
// async: true,
//Use encodeURI to get rid of special characters within richText
data :{title:postTitle,description:encodeURI(postDescription)},
// cache: false,
// processData: false,
datatype: json,
success: successBlock,
error: failureBlock
});