2

I need serialize a string to a standard URL-encoded notation my string has some blank spaces and parentheses:

string = "( 3.141516, 3.1415), 3,1415";

and I need get it at serverside as a only value - var, how can I do that in order to sent it as a query string???

Thanks in advance.

1 Answer 1

7

Without any jQuery at all: encodeURIComponent().

With jQuery, assuming you're using something like $.get():

$.get('http://example.com/', {foo: '( 3.141516, 3.1415), 3,1415'}, callback);

and jQuery will automagically do the URL-encoding for you.

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

3 Comments

,@Matt Ball you know a proper way to use it with $.getscript()?
You have to use encodeURIComponent() since there is no data argument overload for $.getScript(). Just read the API docs: api.jquery.com/jQuery.getScript
yeah, I got it..Thanks @Matt Ball

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.