为什么jQuery.ajax()添加一个参数的网址是什么? [英] Why does jQuery.ajax() add a parameter to the url?

查看:114
本文介绍了为什么jQuery.ajax()添加一个参数的网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 jQuery.ajax()来读取XML文件的获取数据的方法。

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 */}
    } ,                                                                                                                                                         

我的问题是:jQuery的某种程度上增加了一个参数( _ = 1272708280072 ?)的网址,如果有被转义(十六进制)或转义的UTF-8之外的字符ASCII范围 - 我相信 - 在文件名。这一切运作良好,如果文件名不包含字符,在这个范围内。

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.

类型设置为 XML 所以不应该有一个类型的混乱。 XML文件中的头也设置充分。

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

我可以从jQuery的抛出一个错误控制台中看到的,但我不知道在何处的问题,确实是。

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

可能是一个与文件名格式的问题,但我没有找到在网络上的所有资源,以AJAX的文件名规范。任何想法?

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?

感谢您的帮助!

推荐答案

这是一个缓存破坏者,将被忽略。

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.

这篇关于为什么jQuery.ajax()添加一个参数的网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆