$_GET ajax request encoding problems - javascript

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?

Related

Encoding URL into ASCII using javascript

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?

Returning JS from PHP

I'm executing script on one site. I'd like to pass some params to php on other site (even other domain) and include JS which should be returned from php request. Is it even possible to do?
You can try using JSON,
Complete processing your script on site 1, convert the variables into JSON or simply make a post request to the site on another domain.
Grab the JSON or post Input from site 1 and execute the the php script on site-2, now pack the output into a JSON,(don't forget to serialize/escape the output using htmlspecialchars) all you have to do is json_encode.
Return the output to the post request from site-1.
All of this will work. But here is the catch, you must not pass scripts over the air unless you know your script is safe. They can be intercepted and can be hacked. And the input also must be from trusted sources.
You might also want to check your CORS settings.

send unescaped string with XHR (javascript)

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.

Using JQuery AJAX with non-unicode sites

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)

Is it possible to send non POST data with javascript?

I'm trying to submit a postscript print job directly to printer on port 9100. I tried submitting a form directly to the IP and port, but it includes a lot of header information which obviously messes it up.
Is there a way to do this with jQuery or AJAX (or some other term I don't know about)?
You can't do it with Javascript, it'll only do HTTP requests (e.g. POST/GET), which means you get the full HTTP headers included.
Once WebSockets get more widespread, you could use those and send arbitrary data without the HTTP overhead/payload, but at present, that's only in 'bleeding edge' browsers.
This means you're stuck using a Flash or Java applet at present.
You can create a proxy php script which will accept your POST data from the form, format this data and send it to the printer
If you'd like to submit data to this script in background - please see my answer to the following post:
JavaScript: How do I create JSONP?

Categories

Resources