views:

254

answers:

2

Hi,

I have a data fetching method that uses jQuery.ajax() to fetch xml files.

/*    */data: function() {                                                                                                                                          
                                                                                                                                                                /* debug */try {
        var url = arguments[0] ;                                                                                                                                
        var type = arguments[1] ;                                                                                                                               
        var scope = arguments[2] ;                                                                                                                              
        var callback = arguments[3] ;                                                                                                                           

        var self = this ;                                                                                                                                       
            if(this.cache[url]) {                                                                                                                               
                callback(this.cache[url]) ;                                                                                                                     
            } else if(!this.cache[url]) {                                                                                                                       

                $.ajax({                                                                                                                                        
                    type: "GET" ,                                                                                                                               
                    url: url ,                                                                                                                                  
                    dataType: type ,                                                                                                                            
                    cache: false ,                                                                                                                              
                    success: function(data) {                                                                                                                   

                            if(type == "text/xml") {                                                                                                                                                                                                                                                                                
                                var myJson = AUX.json ;                                                                                                         
                                var jsonString = myJson.build(data,scope,null) ;                                                                                
                                var jsonObject = $.parseJSON(jsonString) ;                                                                                      
                                self.cache[url] = jsonObject ;                                                                                                  
                                callback(url) ;                                                                                                                 

                            } else if(type == "json") {                                                                                                         

                                self.cache[url] = data ;                                                                                                        
                                callback(url) ;                                                                                                                 

                            }                                                                                                                                   

                    } ,                                                                                                                                         
                    error: function() {                                                                                                                         
                        throw "Ajax call failed." ;                                                                                                             
                    }                                                                                                                                           
                }) ;                                                                                                                                            

            }                                                                                                                                                   
                                                                                                                                                                /* debug */} catch(e) {
                                                                                                                                                                /* debug */     alert("- caller: signTutor.data\n- " + e) ;
                                                                                                                                                                /* debug */}
    } ,                                                                                                                                                         

My problem is: jQuery somehow adds a parameter (?_=1272708280072) to the url if there are escaped (hexadecimal notation) or unescaped utf-8 characters outside of the ASCII range -- i believe -- in the file name. It all works well if the file name does not contain characters in that range.

Type is set to xml so there should not be a confusion of types. Headers of the xml files are also set adequately.

I can see from the console that jQuery throws an error, but I'm not sure as to where the problem really is.

Probably a problem with file name formatting, but I did not find any resources on the web as to AJAX file name specifications. Any ideas?

Thanks for you help!

+3  A: 

That is a 'cache-buster' and is ignored.

The added parameter changes the url just enough to bypass most all caches that are between you and the source.

If the Url was not modified, it is likely that data would be served from any one of the caches between you and the resource, including your browser, any proxies, and perhaps the server itself.

You can find a lot of explanations on the net. Here is one.

Sky Sanders
Ok, great. Seems like that wasn't the problem, though. My ajax call returns 404 - file not found if there are utf-8 characters in the file name. Any ideas on that?
FK82
@FK82- although there are some emerging technologies that can handle UTF urls, http is traditionally ASCII so you need to UrlEncode any url that may contain UTF characters. b.t.w. '?_=1272708280072' is ascii so that is not the problem.
Sky Sanders
The utf-8 in the file name was already escaped by a java servlet, which prepares the file. So it is already encoded in hexcode like `%20%20%20` (just an example). Format therefore is like `filename_%20%20%20.xml`. The problem seems to be with Tomcat, as it replaces the `%` character with `%25` which is the corresponding hexcode. So, I will need a solution for encoding the special characters, that does not get parsed by Tomcat. I should be able to figure that out myself. Thanks for your help!
FK82
+1  A: 

it should be ignored.

just to make a test, if you are using rails, don't use the javascript_include_tag but pass the javacript as

<script src="/path/for/the/script/script.js" type="text/javascript"></script> 

It won't enable the cache-buster and with that you can see if your problem is where you think that it is.

VP
Cache buster probably is jQuery's as is set the `cache: false` flag. The problem seems to be another one though. Have a look at the above comment, if you like.
FK82