I am sending UTF-8, japanese text, to my server. It works in Firefox. My access.log and headers are:
/ajax/?q=%E6%BC%A2%E5%AD%97 Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Content-Type application/x-www-form-urlencoded; charset=UTF-8
Howeer, in IE8, my access.log says:
/ajax/?q=??
For some reason, IE8 is turning my AJAX call into question marks. Why!? I added the scriptCharset and ContentType according to some tutorials, but still no luck.
And this is my code:
$.ajax({ method:"get", url:"/ajax/", scriptCharset: "utf-8" , contentType: "application/x-www-form-urlencoded; charset=UTF-8", data:"q="+query ..., ... })
Ajax (Asynchronous JavaScript And XML) allows web pages to be updated asynchronously by exchanging data to and from the server. This means you can update parts of a web page without reloading the complete web page.
ajax post method. The reason was my response was not in the JSON format so there was no need for the dataType: 'json' line in the submit method. In my case, the returned response was in text format that's why it was not going to success event. Solution: Remove dataType: 'json' line.
jQuery provides several methods for AJAX functionality. With the jQuery AJAX methods, you can request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post - And you can load the external data directly into the selected HTML elements of your web page!
Try encoding the query parameter with encodeURIComponent()
data:"q="+encodeURIComponent( query )
as bobince very correctly noted in his comment, if you use the object notation to pass parameters to the ajax method it will handle the encoding itself..
so
data:{ q : query }
will make jQuery handle the encoding ..
I'we read this post hoping it would solve the problem I had came across and that had to do with utf8 conversions.
In my case it turned out that the server engine (node.js) calculating the Content-length of the data with the data considered to be raw and not utf8, thus two character extended chars in uft8 was calculated as if they where one char resulting in the server sending one character too little.
See what I did to solve it here: Not well formed Json when sending to CouchDB
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With