xml – jquery: how to escape strings? – Education Career Blog

I have an xml string that wanted to be sent to server:

        <script type="text/javascript">
                $(document).ready(function() {
                // put all your jQuery goodness in here.
                $('#button').click(function() {
                        $.post('http://localhost/a.bc', { cmd:"<cmd cmd_name='login_user'><login_user user_name='binc1' password='pp'/></cmd>"},  function(data) {


The white space inside the xml is replaced to ‘+’ when server got it.
Is it possible that I can escape the xml by myself before use $.post so that it will send the escaped version to server. I can unescape the string in the server side.

Or even better, can I send pure XML to server without any escape/unescape dirty things?


If you want to escape the string, the JavaScript escape() function is at your disposal.


You could just use a JavaScript function like encodeURIComponent. Check out the link below for usage and examples.


Leave a Comment