I have an application in Java EE and I have my database in ISO-8859-1, thus I need do the jsp encoding in ISO-8859-1... (all my pages are in iso-8859-1)
I have a jsp with a javascript code, which does a request to a Struts action.
This is my js code.
$.ajax({
type:'GET',
encoding:'iso-8859-1',
contentType: 'text/html;charset=ISO-8859-1',
url: xUrl,
success: function(){
$("#MensajeOk").attr('style','display:block');
$("#MensajeOk").delay(10000).slideUp(1000);
}
});
with IE and Chrome all is correct, because it does the request coding in ISO-8859-1 but Firefox encodes the request in UTF-8 and this is a problem for me, because in server side I need ISO-8859-1 and with FF there are some characters than i can't recover.
mi form is
<html:form action="/action.do" acceptCharset="iso-8859-1">
<input type="text" name="title">
and my java code is
new String((request.getParameter("title")+"").getBytes("iso-8859-1"),"iso-8859-1"));
with it, I can recover fine the text with IE and Chome, but fails with Firefox.
Other option will be send the request in UTF-8 encoding by encodeURI('data') but in the server side I can't convert the text from UTF-8 to ISO-8859-1...
Some idea???
Thanks a lot and sorry for me english!!
looking at the documentation, there doesn't seem to be an option called encoding - but theres a nice little hint (including the solution to your problem) on the contentType-option:
Data will always be transmitted to the server using UTF-8 charset; you must decode this appropriately on the server side.
so it seems like firefox is right and the other browsers do it wrong - try to remove the encoding-option and to a serverside conversion.
Related
I developed a webapplication with ajax.
its fine with firefox but under IE8 some of my ajax dynamics (e.g. changing a div after a button etc.) are not working. only if I disable the browser-cache (F12 - Cache - always reload from server).
think IE doesnt check that a ajax-response has changed a part of the site or something else.
any ideas i can handle this with this option on??
I tried random-numbers in the request or timestamps in the response but didnt work.
thanks!
ch
try with.
$.ajaxSetup({ cache: false });
Not sure what server side language you use... I used code below at the server side(in the ...aspx.cs file):
Response.AddHeader("Cache-Control", "No-Cache");
Response.Write...
I am using the YUI 2.7 Ajax (Connection Manager) api and would like to know how to override the content type of the connection manager especially character set.
The problem is that when registered trademark character (R) (Alt+0174) is sent to server using Ajax request its getting converted into Unicode and showing "?" on server side. As our system does not support Unicode db all such characters appear as "?" in the system. After initial analysis we have found that character set is set to UTF-8 for the content type ajax request header. So thought that it might be the issue.
On server side we are using ASP.NET
Any pointers would be helpful.
Just put this in your code and all your ajax transactions will have this custom header:
YAHOO.util.Connect.initHeader('Content-Type', 'application/json; charset=utf-8', true);
Take a look at the example shown on the page for Request Signatures, it shows setting a custom header. Overriding default headers should work the same way.
I am using jQuery form plugin to upload images in my MVC project.
For some reason the Code in IE no longer working (worked before):
I can tell the submit is successful, image is successful uploaded, and recoded in database, however the response seems somehow corrupted in IE.
function showResponse(responseText, statusText, xhr, $form) {
$("#loading").hide();
AddImage(responseText.ImageId);
buildArray();
}
I tested on Firefox, Chrome, Safari, it all working fine, however when i use it in IE.
I got error:
Message: 'ImageId' is null or not an
object
Anyone have had any similar problem before?
Thanks in advance!
Well the problem solved by changing the content type from "text/plain" to "text/html", that's it.
OMFG, Internet Explore!
Code I have changed:
return Json(newImage, "text/html", Encoding.Unicode, JsonRequestBehavior.AllowGet);
hope that would help someone else as well.
As said in the documentation about File Uploads:
It is important to note that even when the dataType option is set to 'script', and the server is actually responding with some javascript to a multipart form submission, the response's Content-Type header should be forced to text/html, otherwise Internet Explorer will prompt the user to download a "file".
I don't know it worked before, but the documentation is clear about this concern.
I want use $.ajax to read some infomation from xml file,here is my js code :
$.ajax({
type: "get",
url: "Database/App_all.xml",
dataType: "xml",
timeout: 2000,
beforeSend: function () {
},
success: function (xml) {
$(xml).find("app[id='id-1']").appendTo($("#contain"));
},
error: function () {
alert("ajax failed!");
}
});
However, the code only work great in firefox and opera.
It doesn't work in chrome(7.0.517.24 ) and safari(5.0.1),failed without any alert,not even the alert("ajax failed").
Is there any bug in $.ajax in chrome and safari?so how to solve the problem?
thank you very much:)
You should use chrome's or safari's built-in developer tools (ctrl+shift+i) to track JS errors and track actual AJAX requests.
Is your code wrapped in document.ready? Is there any erros in javascript console? Also try to output something after success callback line.
Another cause for this could be incorrect mime-type for your XML file returned by server. It should be [Content-type: text/xml]. You can check that in chrome's or safari's built-in developer tools - just look for headers tab when xml resource is selected. If it 's actual problem, you may need to tweak web-server configuration (main config or .htaccess for apache) to return correct mime-type.
First thank you gajendra.bang and Māris Kiseļovs give me your advices,I have konw what's wrong with my code,after I get a bad resault ,I trying to know what the $.ajax get from xml exactly,so I use firebug check the div#contain I found that:
<div id="contain">
<auther>cocept</auther>
</div>
yes,I think the <auther></auther> must the problem,I don't even konw the $.ajax would get the tagname as well
so I rewrite it :
success: function (xml) {
$("#contain").html($(xml).find("app[id='id-1']").find("auther").text());
}
then the div$contain is:
<div id="contain">
cocept
</div>
so ,the chrome and safari could show again!
I suppose you have problem with reading of the local file per ajax. Ajax can be used to read a file from the same web server, but there are some security restriction if you read it not per HTTP.
In firefox and opera you can read local files (with url like file:///C:/Program%20Files/My/Database/App_all.xml) per ajax without any problem.
In Internet Explorer you should use dataType: 'text' and then convert the text to XML (read more here).
To be able to read local files in Chrome you have to restart chrome with another parameters:
chrome.exe --allow-file-access-from-files
(Be sure that all other instances of chorme closed before starting Chrome.exe in the way).
This is a problem for local files... You should try uploading them on a web server and check from there
$(xml).find("app[id='id-1']").appendTo($("#contain"));
what is xml basically returning, an element with "#" like "#mydiv" or class like ".mydiv"
I think you are trying to access an element and if you are not returning it with "#", try
$("#"+xml).find("app[id='id-1']").appendTo($("#contain"));
One of the request parameters in an http request made by the client contains Japanese characters. If I make this request in Firefox and look at the parameter as soon as it reaches the server by debugging in Eclipse, the characters look fine. If I do the same request using IE 8, the characters get garbled when I look at them at the same point in the server code (they are fine in both browsers, though). I have examined the POST requests made by both browsers, and they both pass the same sequence of characters, which is:
%2C%E3%81%9D%E3%81%AE%E4%BB%96
I am therefore thinking that this has to do with the encoding. If I look at the HTTP headers of the request, I notice the following differences. In IE:
Content-Type: application/x-www-form-urlencoded
Accept: */*
In Firefox:
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
I'm thinking that the IE 8 header doesn't state the UTF-8 encoding explicitly, even though it's specified in the meta tag of the HTML document. I am not sure if this is the problem. I would appreciate any help, and please do let me know if you need more information.
Make sure the page that contains the form has UTF-8 as charset. In IE's case, the best thing to make sure of this is by sending a HTTP header ('Content-Type: text/html; charset=utf-8') and adding a meta http-equiv tag with the content type/charset to your html (I've seen this actually matter, even when the appropriate header was sent).
Second, your form can also specify the content type:
<form enctype="application/x-www-form-urlencoded; charset=utf-8>