views:

88

answers:

1

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 the best way to pass the content back to the controller, save it, and return back to the same page?

+3  A: 

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"]
Trickster
I am using linq to sql, and plan to just save the data into a table.
Grayson Mitchell
Once I get the dat aback to the controller I will be fine, I just have no idea how to formulate the jquery
Grayson Mitchell
I've updated my post. Hope it'll be useful
Trickster
awesome! This looks like what I want! I am getting 'an error occurred: undefined' ... I am guessing that this must be the url line (mine is "/ttas/test", will get back when I work out what is happening.
Grayson Mitchell
maybe the 'ed' variable is undefined in this scope? do you use something like firebug? or maybe IE debugger (shortcut F12)?
Trickster
I have got the url to work1\ If I remove the url line, it works. It just returns to the calling controller, and I just test to see if it is a post.2\ url: "savetext" works!
Grayson Mitchell
Thanks for all your help, nice end to the year getting this going.
Grayson Mitchell