I'm using JQuery '.serialize' + '.post' to send form data using ajax to a non-unicode, asp based website. The result data is url-encoded in unicode (characters are encoded in double values).
Can I post the form data encoded like it's sent using the form submit(), using JQuery ajax?
Ok, after hours and hours of trying...
Javascript uses UTF-8 for strings, and AJAX requests are always sent with UTF-8, period. There will always be a conversion on the server side if UTF-8 is not supported.
Description in the JQuery contentType parameter states:
Data will always be transmitted to the server using UTF-8 charset; you
must decode this appropriately on the server side.
So, eventhough there are QA's which claim some solutions as working, they are simply some conversions on the client & the server side. So firefox's firebug will always show UTF-8 characters on the net panel for AJAX requests, and it will never look like a submitted form with single byte characters.
You can use
var encStr = encodeURIComponent(str)
Related
I am writing a php script-wrapper for my API encode/decode requests and responses. The php script works fine with forms but I can't send properly encoded requests using javascript (angular)
In details:
I have an encoded request (on client side):
{"ct":"2UExUFiKFiZeT73AbLWYrCzJZnYUuCaaLq6VKcaboj/VQxDIrRXa6b4FvbVJXgU9","iv":"5c37e23d740ceb7611cb707bacd66633","s":"11bd03dda58ffbbe"}
The form converts this request into
%7B"ct"%3A"2UExUFiKFiZeT73AbLWYrCzJZnYUuCaaLq6VKcaboj/VQxDIrRXa6b4FvbVJXgU9%3D%3D"%2C"iv"%3A"5c37e23d740ceb7611cb707bacd66633"%2C"s"%3A"11bd03dda58ffbbe"%7D
It works, but I need to replicate it using angular http.get()
http.get doesn't convert this request properly. I tried to use encodeURI() but it doesn't help, obtain:
"%7B%22ct%22:%222UExUFiKFiZeT73AbLWYrCzJZnYUuCaaLq6VKcaboj/VQxDIrRXa6b4FvbVJXgU9%22,%22iv%22:%225c37e23d740ceb7611cb707bacd66633%22,%22s%22:%2211bd03dda58ffbbe%22%7D"
It converts quotes, what based on the previous example I don't need
Do you have any ideas?
I have a page in wich the user will write a code (in a programming language). the code can be very long (more than 2000 characters) and can contain any type of characters. And when he press the send button the code will be sent (using javascript ajax) to a script file on the server etc..
currently i am using this to send the code with ajax :
jxobj.open('POST', 'www.my-website.com/my_script.php', true);
jxobj.send('code=' + code);
but if the code contains some characters like & then the value of code will be broken into many pieces and i can't retrieve it in my script file.
Is there any way to send ajax request without a string concatenation? I would like to use only javascript if possible and thanks.
The data format is well documented and the standard JavaScript encodeURIComponent function will encode data for it.
jxobj.send('code=' + encodeURIComponent(code));
Is there any way to send ajax request without a string concatenation?
Not really. The send method takes a string, so you have to build a string using some mechanism or another. You could achieve it with (for instance) arrays and joins, but it still comes down to the same basic principles.
I have string containing javascript file content and I need to upload it to server (it's not part of server side code - it's used only for development (on-site code editing) process so security is not important). PHP script uses file and content variables. I found only implementations where xhr.send() argument was string in standard GET format (var1=sth&var2=sthelse) but I'd like to send this string without any encoding / decoding / escaping / unescaping on server side. As it's js it contains all possible characters including '&' or '='.
Is it possible to pass data to POST in other way than using standard query?
I'm rather not interested in jQ solution
Sending JS file contents in a query string parameter is not a good idea. A few points:
If your situation support HTML5 you can send files to your server with JS.
If you don't want to send as a file upload I would send it as POST data.
Any data encoded or escaped on the client can be decoded or unescaped on the server. In some setups this is automatically done for you. There's no reason to avoid this if it's the proper way to handle data.
Am trying to send a variable from javascrpt client code, to php script at server side using ajax, the php scripts accepts a value from the script and makes query in database according to this value...the problem that am having an encoding issue, when i try to send a value with a special characters language (arabic) the query to the database fails in Google Chrome, and in Internet Expolrer, but it works fine in mozilla FF...is it common to have this encoding problem with ajax?? any sugestions?
I am using Ajax to retrieve images from a remote server. First I try this directly using the URL of the remote server - the returned image is a string(since that's how Ajax communicates). I use the Javascript fromCharCode and CharCodeAt to convert the data back to binary and then the window.btoa() to display it. This works. Then I want to transfer this image through an overlay network (P2P). I intercept the Ajax request, transfer it to the server through the P2P network and then retrieve the response in []byte array. But now I need to know to what type of string I should convert the byte array before I feed it back to the calling Ajax client. If I use Base64 or simply convert the byte array to string it does not display the image correctly.
Anyone has tried working with something like this before?
I will appreciate any feedback very much. Thanks
Javascript doesn't have different kinds of strings.
The desired character set will be the same one the web page is encoded in, ideally UTF-8.
Have you compared the response sent by the P2P server to the response sent by the original server? Is there some kind of wrapper that's missing, or perhaps an important MIMEtype difference?