开发者

jquery: how to escape strings?

开发者 https://www.devze.com 2023-01-21 05:36 出处:网络
I have an xml string that wanted to be sent to server: <script type=\"text/javascript\"> $(document).ready(function() {

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) {
                                        alert(data);
                                          $('.result').html(data);
                                          });
                                });
        });

        </script>

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开发者_C百科/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.

http://www.w3schools.com/jsref/jsref_encodeURIComponent.asp

0

精彩评论

暂无评论...
验证码 换一张
取 消