1

I was wondering how to access file addresses containing latin characters, with jquery ajax. I tried to retrieve data in xml files with the script below:

$.ajax({
    type:'get',
    url:encodeURI('configuration/'+(value).toLowerCase()+'.xml'),
    dataType:'xml',
    contentType:'application/x-www-form-urlencoded;charset=utf-8;',
    success:function(content){
        $('#content').html($('content',content).text().replace('nL','<br/>'));
    });
});

but the problem surges when I try to access xml files whose addresses' contain unicode characters like intrusão.xml.

It keeps loading and nothing happens. Below are are the contents of the xml file example named intrusão.xml:

<?xml version="1.0" encoding="utf-8"?>
<document>
    <content>First line.nLSecond line.</content>
</document>
Shef
  • 44,808
  • 15
  • 79
  • 90
user722756
  • 633
  • 1
  • 5
  • 9
  • 1
    If you use a tool like Fiddler or Firebug to monitor the GET request, what is the value of the URI that is actually sent to the server? If you add an error callback function to the object passed to $.ajax, what is the value of the exception argument or status of the XHR argument? – dgvid Oct 01 '11 at 16:02
  • are you able to retrieve the file directly in your browser?, that is by entering the URL directly in the location bar of your browser. – Xint0 Oct 01 '11 at 16:06
  • well i can access it in my home server but not in my hosting server. when i check error.log on my hosting server it renders a message similar to following: File does not exist: html/configuration/submenus/intrus\xc3\xa3o.xml, intrus\xc3\xa3o.xml corresponds to intrusão.xml – user722756 Oct 02 '11 at 08:55
  • i'm not able to access the file directly through my browser. I receive an error message telling /configuration/submenus/intrusão.xml was not found on this server. – user722756 Oct 02 '11 at 08:58
  • I changed already default char setting on my hosting server to utf-8 to see if it results but i'm getting same error. – user722756 Oct 02 '11 at 09:00

2 Answers2

1

I recomend you to read this

They give some solutions , but always modifying encoding:

  • Changuing Ajax & php encoding

  • Convert string encoding (example : $str=iconv("windows-1250","UTF-8",$str);)


I would be embarrased to copy solution (not fair) , then , read that thread i have link before

Community
  • 1
  • 1
A.Quiroga
  • 5,704
  • 6
  • 37
  • 58
  • i found out that it's for php but what i'm needing is for ajax because ajax is that makes the request, so solution must be for ajax. The file that calls this is an html not a php. Thank you for your attention. – user722756 Oct 02 '11 at 10:51
0
  1. change this may resolve the problem

    url: 'configuracao/submenus/' + encodeURI((value).toLowerCase()) + '.xml')
    
  2. It is possible that the server does not support non-ascii chars. check this.

amiry jd
  • 27,021
  • 30
  • 116
  • 215
  • it didn't solve my problem. Still not able to access file containing a tilde. but thank you for suggestion. – user722756 Oct 01 '11 at 10:55
  • i tried also url:encodeURI('configuration/submenus/'+escape(value.toLoweCase())+'.xml') and nothing happen. I'm able to access other files that don't contain latin charset, so problem lies on characteres used on filename. So i can't rename the file to a name without latin characters because i need it to contains latin characters. Thank you. – user722756 Oct 02 '11 at 10:54
  • I changed the default charset of my hosting server and didn't solve too. – user722756 Oct 02 '11 at 10:59