为什么 jQuery.ajax() 给 url 添加参数? [英] Why does jQuery.ajax() add a parameter to the url?

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

问题描述

我有一个使用 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
- " + e) ;
                                                                                                                                                                /* debug */}
    } ,                                                                                                                                                         

我的问题是:如果有 ASCII 范围之外的转义(十六进制表示法)或未转义的 utf-8 字符,jQuery 会以某种方式向 url 添加一个参数 (?_=1272708280072) -- i相信 - 在文件名中.如果文件名不包含该范围内的字符,则一切正常.

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 设置为 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.

添加的参数更改了 url,足以绕过您和源之间的大多数缓存.

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

如果 Url 没有被修改,数据很可能会从您和资源之间的任何一个缓存中提供,包括您的浏览器、任何代理,或许还有服务器本身.

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() 给 url 添加参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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