I have simple xml:
<?xml version="1.0" encoding="utf-8"?>
<category><title>Привет!</title></category>
When I get it from cloud code (parse.com) like this:
...
Parse.Cloud.httpRequest({
url: 'http://path_to_xml/my_file.xml',
headers: {
'Content-Type': 'text/xml; charset=utf-8'
},
success: function(httpResponse) {
console.log(httpResponse.text);
}
...
In log I see:
<?xml version="1.0" encoding="utf-8"?>
<category><title>ÐÑивеÑ!</title></category>
Xml file is in UTF-8 encode.
And it is not problem of log, because when I put httpResponse.text to string in object I see the same problem.
May be parse.com do not support UTF-8?
Thank You!
Ok the problem is that Cyrillic characters are using ISO-8859-5, so you are converting in utf8 and it's not reversible. Try to declare <?xml version="1.0" encoding="ISO-8859-5"?> and see the results.
Related
my work consist to read this distant xml file :http://www.velib.paris/service/stationdetails/paris/901 ,in html file by using Ajax !
this is my code:
<script type="text/javascript">
getReadXmlFile();
function getReadXmlFile(){
alert("recherche d fichier");
$.ajax({
type: "GET",
url: "http://www.velib.paris/service/stationdetails/paris/901",
dataType: "xml",
success: parseXml
});
alert("obtention du fichier");
}
function parseXml(xml){
alert('debut du parse');
var up=$(xml).find("updated").text();
alert(up);
}
</script>
But it does not run i don know why
thank for help ! i need your help please !
I have tried your code at JSFiddle (with unrelated modification) and it works properly.
getReadXmlFile();
function getReadXmlFile(){
alert("recherche d fichier");
$.ajax({
type: "POST", // JSFiddle needs this, it's not related to your issue
url: "/echo/xml/",
dataType: "xml",
data: {
xml: `
<?xml version="1.0" encoding="utf-8"?>
<station>
<available>1</available>
<free>19</free>
<total>20</total>
<ticket>1</ticket>
<open>1</open>
<updated>1472183109</updated>
<connected>1</connected>
</station>
`
},
success: parseXml
});
alert("obtention du fichier");
}
function parseXml(xml){
alert('debut du parse');
var up=$(xml).find("updated").text();
alert(up);
}
Check this JSFiddle
Without error message given, the only thing I can think of is do you have jQuery loaded correctly?
I have a cloud function that send http request to a URL that returns JSON string using Parse.Cloud.httpRequest.
Eventually my cloud function returns this JSON to android client.
When this JSON is received on the client, all the properties that include Hebrew letters are simply removed.
I added this to the headers of Parse.Cloud.httpRequest :
'Content-Type': 'application/json;charset=utf-8'
but it didn't help.
Any idea how it can be fixed?
Thank you
Parse.Cloud.define("getReport", function(request, response) {
return Parse.Cloud.httpRequest({
url: 'http://www.url-that-returns-json.com',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
}).then(function(httpResponse) {
// success
response.success(httpResponse.text);
console.log(httpResponse.text);
},function(httpResponse) {
// error
console.error('Request failed with response code ' + httpResponse.status);
});
});
I sent a bug report to Parse.
Now this bug seems to be fixed.
Please, try again.
https://developers.facebook.com/bugs/1596679710611808
What is the difference between
$.ajax({
type: "GET",
url: "logs/old-vs-new.xml",
dataType: "xml",
success: function(xml) { ...
And
$.ajax({
type: "GET",
url: "logs/old-vs-new.xml",
dataType: "html",
success: function(xml) { ...
I know the dataType is different. But when I use datatype xml I get the parsererror and with datatype html it works fine. It's strange because my file I want to work with is a XML file.
My XML file consist now out of more than 5000 lines, but when a decrement it to about 800 lines it works too with datatype XML.
Someone an idea?
My problem is solved.
My markup wasn't right.
I used special chars between my tags and that was my fault. Now i edited my code and replaced the special chars with html entities.
So peoples with the same problem as me, first try to validate your xml code with a validator which you can find on the web.
Thanks Tony Hopkinson and florin.prisecariu!
I need to spend Spanish text in json response. I have tried all the possible ways but the message still shows weird characters on the UI. The message I want to show is,
Número de Seguro Social
But it shows up as,
N�mero de Seguro Social
On the Java side,
//response.setContentType("application/json");
//response.setCharacterEncoding("UTF-8");
response.setContentType("application/json;charset=utf-8");
OutputStream out = null;
out = response.getOutputStream();
out.write(jsonResponse.toString().getBytes());
out.close();
added meta tag in head section.
<meta http-equiv="content-type" content="text/html;charset=utf-8">
I have also set the content type in ajax call
$.ajax({
async: false,
cache: false,
type: get,
contentType: "application/json; charset=utf-8",
url: //url,
data: //data,
dataType: //dataType,
success: //callbackfn,
error: //errorfn
});
Nothing seem to work. Is there anything else I can do to get the special characters work as I intended?
I would test where the error is occurring first by sending the string:
"N\u00famero de Seguro Social"
To the browser that is showing the UTF string, just to make sure that it is capable of understanding and displaying the UTF string you're trying to display.
But the actual problem is probably in:
out.write(jsonResponse.toString().getBytes());
As getBytes will get the bytes for the default charset for the system, which may not be UTF-8. You can check this by calling Charset.defaultCharset();
I'm guessing jsonResponse is your own class for storing the response data and then converting it to JSON at the end. I'd recommend using a library from http://www.json.org/ like the Google JSON library for doing the JSON conversion, as there are lots of little gotchas like this one, that are solved problems, so long as you use a decent library to do the encoding/decoding.
$.ajax({
type: "Get",
url: your url,
data: { inputParam : JSON.stringify(inputParam)},
dataType: "json",
success: //callbackfn,
error: //error
});
I use jquery and ajax to submit UTF-8 text, to ensure everything is utf-8, I've put the following in web.config:
<globalization
fileEncoding="utf-8"
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-US"
uiCulture="en"
/>
Jquery code:
$.ajax({
url: "#Url.Content("~/Home/EditProductTranslations/")",
type: "POST",
data: $(this).serialize(),
contentType: "application/x-www-form-urlencoded;charset=UTF-8",
scriptCharset: "utf-8" ,
success: function (result) {
//$('##resultDiv').html(result);
var info = $("<span class='successMsg'></span>").hide().html(result);
info.insertAfter(curSubmit).fadeIn(300).delay(2700).fadeOut(400, function () {
$(this).remove();
});
}
});
I've also verified it's UTF-8 data by using notepad++ to convert it to UTF-8 (though when it was pasted it said it was UTF-8 already and the data displays perfectly on a UTF-8 site). But I just get ???????? instead of cyrillic signs when I save the form.
The Layout file of the project also has UTF-8 declaring meta-tags, I've done all the usual stuff. Tried to run the submit on firefox with firebug running and it seems everything is submitted correctly? Do I need to declare UTF-8 inside the controller or what?
Add ;CharSet=utf8 to the connection string