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?

1 Answer 1

3

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"]
Sign up to request clarification or add additional context in comments.

6 Comments

I am using linq to sql, and plan to just save the data into a table.
Once I get the dat aback to the controller I will be fine, I just have no idea how to formulate the jquery
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.
maybe the 'ed' variable is undefined in this scope? do you use something like firebug? or maybe IE debugger (shortcut F12)?
I have got the url to work 1\ 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!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.