我在MVC页面中使用TinyMCE控件,现在我想保存控件的内容(希望使用ajax以便页面不再呈现)...我有一些看起来像这样的javascript:< / p>
mysave = function() {
var ed = tinyMCE.get('content');
// Do you ajax call here, window.setTimeout fakes ajax call
ed.setProgressState(1); // Show progress
window.setTimeout(function() {
ed.setProgressState(0); // Hide progress
alert(ed.getContent());
}, 3000);
};
将内容传回控制器,保存并返回同一页面的最佳方法是什么?
答案 0 :(得分:3)
好吧,使用jQuery.ajax。 http://docs.jquery.com/Ajax。我建议你使用POST请求,这样你就可以传输任意长文本。
您打算如何保存文字?你使用任何数据库引擎吗?我们需要更多信息。
$.ajax({
url: "/controller/savetext",
cache: false,
type: "POST",
data: { text: ed.getContent() },
success: function(msg) {
alert("text saved!");
},
error: function(request, status, error) {
alert("an error occurred: " + error);
}
})
在服务器端这样的事情:
string text = Request.Form["text"]