开发者

asp.net mvc how to save data from jquery control

I am using the TinyMCE control in a MVC page, and now I want to save the content of the control (hopefully with ajax so the page is not rendered again)... I have some javascript that looks like this:

 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);
};

What is t开发者_如何学Pythonhe best way to pass the content back to the controller, save it, and return back to the same page?


well, use jQuery.ajax. http://docs.jquery.com/Ajax. I suggest you to use POST request so you can transfer arbitrary long texts.

How do you plan to save the text? Do you use any database engine? we need more information.

$.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);
    }
})

and on server side something like this:

string text = Request.Form["text"]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜