Paul
Paul

Reputation: 1006

Javascript encode function and unicode

Im using ASP.NET MVC and the kendo ui editor and jquery ajax.

Basically if I have a £ character in the kendo ui editor and post the contents to the server using ajax with this code :

$.ajax({
    url: "/API/saveContent",
    data: "content=' + escape($("#textContent").data("kendoEditor").value()),
    type: "POST", dataType: 'json', async: false,
    success: function (data) {},
    error: function () { alert('ajax error'); }
});

What I end up with on the server is a ? character rather than a £.

The html page is UTF-8, so the ajax call to the server is unicode and the javascript escape function isnt working in a unicode way, its just using the extended ascii character set and encoding the £ as : %A3

Is there a way in javascript to do this escape functionality with unicode, I think I want to end up with : %C2%A3 (i worked this out by having a UTF-8 html page and put £ in a text box and submitted the form and in fidler it showed this has been content in request body of the post).

Upvotes: 1

Views: 890

Answers (1)

Musa
Musa

Reputation: 97672

You should use encodeURIComponent instead of escape

data: "content=" + encodeURIComponent($("#textContent").data("kendoEditor").value()),

Upvotes: 1

Related Questions