views:

21

answers:

2

I am trying to post some HTML information to a url using the ajax post command

var html = "<b>bold</b>";

$.ajax({
    type: "POST",
    url: "/DragDrop/GetData/" + id + "?html=" + html,
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
    }
});

But of course you can't pass html in the URL, I know this is something easy but it is driving me nuts, how do I do this?

+2  A: 

You are doing a POST. Why are you trying to pass the content in the URL instead of using data?

var html = "<b>bold</b>";

$.ajax({
    type: "POST",
    url: "/DragDrop/GetData/" + id,
    data: html,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
    }
});
Yakimych
Yes, this would work.Issue I have now is on the c# side my public ActionResult GetData(string id, string html); The variables are all null?
Coppermill
What does your route for GetData look like? You can also try `data : {html : html}` in your ajax call.
Yakimych
yes that is correct, it does not allow content that has tags in e.g. Hello <b>world</b> it gets ignored
Coppermill
Have you tried `escaping` the string? `var html = escape("<b>world</b>")`.
Yakimych
A: 

If you really wanted to pass it through query string, you would have to encode it. Here's a jQuery package for encoding it:

http://plugins.jquery.com/project/URLEncode

Shlomo