0

I am using jquery ajax api to submit (POST/GET) a text as parameter to a processing page.

<input type="text" id="txtboxdata" name="txtboxdata" >

var dataString = "tmpVar="+ escape( $("#txtboxdata").val() );
$.ajax({ type: "POST", 
                  url: "processing.jsp",
                  data: dataString ,
                  dataType: "json",
                  success: function(){}
        });

//dataString holds the parameter and value to be passed. Value is retrieved from a text box.

If the text box

  • contains UTF-8 characters
    and
  • apply the javascript "escape" on the text box value

then the parameter tmpVar goes disappears from the request object in the processing page(processing.jsp).

I used the debugger, and checked the request object. The parameter called "tmpVar" never shows up.

This works correctly when the following conditions are met
tmpVar shows up in the request object of processing.jsp when

  • there are no UTF-8 characters.
  • I do not apply "escape" before making the ajax call.

My Question I would like to understand why does applying escape on a text containing UTF-8 not show up in the request object?

PS: I used "form serialize()" to solve the problem, just trying to understand why the issue occured.

Firebug: looks fine, this always shows up correctly. No missing data before the actual POST/GET.

1
  • What does the HTTP request look like when sending the request that results in the tmpVar variable not being seen? Use Firebug or Chrome to capture these and post them Commented Jun 2, 2011 at 13:51

2 Answers 2

1

You should call encodeURIComponent instead.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for providing the alternate method. This made me do some research and I found a good explanation.
1

Using the answer provided by @SLaks did some more research and found a satisfactory answer.

Explains why "escape" shouldn't be used and compares it with other method which can be used.

  • encodeURIComponent()
  • encodeURI()

http://xkr.us/articles/javascript/encode-compare/

Comments

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.