(Sorry about my english, it aint my birth lang) I have a project that uses codeigniter+JqueryUI. I was thinking about upgrading JQuery version to 1.5 mainly because I am using a lot of ajax calls, and any improvement in speed is highly appreciated. So this is my code, wich works fine in JQuery version 1.4.4:
(抱歉我的英文,它不是我的出生郎)我有一个使用codeigniter + JqueryUI的项目。我正在考虑将JQuery版本升级到1.5,主要是因为我使用了大量的ajax调用,并且对速度的任何改进都非常感激。所以这是我的代码,在JQuery 1.4.4版中运行良好:
$("#nome_produto").autocomplete({
source: function( request, response ) {
$.ajax({
async:false,
url: "<?php echo site_url("produtos_produto/json_produtos/f") ?>",
dataType: "json",
type: "POST",
data: request,
success: function( data ) {
response( $.map( data, function( item ) {
return {
label: item.label,
value: item.label,
cod: item.cod
}
}));
},
beforeSend:function(){
$("#nome_produto").toggleClass("loading");
},
complete:function(){
$("#nome_produto").toggleClass("loading");
}
});
},
minLenght:3
});
In Jquery 1.5, I got a 404 error, but the url requested is this: http://myurl.com/produtos_produto/json_produtos/f?callback=JQUERY_hashofnumbers, even though this is a post request. Does anyone knows why it happens?
在Jquery 1.5中,我收到了404错误,但请求的URL是:http://myurl.com/produtos_produto/json_produtos/f?callback = JERY_hashofnumbers,即使这是一个帖子请求。有谁知道为什么会这样?
2 个解决方案
#1
5
might be related to this ticket: http://bugs.jquery.com/ticket/8084 the quick fix is:
可能与此票证有关:http://bugs.jquery.com/ticket/8084快速解决方法是:
jQuery.ajaxSetup({ jsonp: null, jsonpCallback: null});
before doing ajax calls
在做ajax调用之前
#2
2
check for hidden redirects
检查隐藏的重定向
in my case I am using Django, where, in general, all URL's end with '/'
在我的情况下我使用的是Django,一般来说,所有的URL都以'/'结尾
If a request is made for a URL not ending in '/' and the resource cannot be found then Django issues a redirect to that same URL with '/' appended (It's a generally useful option in Django).
如果请求的URL不是以'/'结尾,并且找不到资源,那么Django会发送一个重定向到同一个URL并附加'/'(这是Django中一个非常有用的选项)。
In my javascript I had accidentally omitted the trailing '/' in my POST request. This resulted in a redirect (to the correct url). However apparantly POST is automatically converted to GET during a redirect (see e.g. https://*.com/a/10586852/473285).
在我的javascript中,我不小心在POST请求中省略了尾随'/'。这导致重定向(到正确的URL)。但是,在重定向期间,POST会自动转换为GET(例如,请参阅https://*.com/a/10586852/473285)。
#1
5
might be related to this ticket: http://bugs.jquery.com/ticket/8084 the quick fix is:
可能与此票证有关:http://bugs.jquery.com/ticket/8084快速解决方法是:
jQuery.ajaxSetup({ jsonp: null, jsonpCallback: null});
before doing ajax calls
在做ajax调用之前
#2
2
check for hidden redirects
检查隐藏的重定向
in my case I am using Django, where, in general, all URL's end with '/'
在我的情况下我使用的是Django,一般来说,所有的URL都以'/'结尾
If a request is made for a URL not ending in '/' and the resource cannot be found then Django issues a redirect to that same URL with '/' appended (It's a generally useful option in Django).
如果请求的URL不是以'/'结尾,并且找不到资源,那么Django会发送一个重定向到同一个URL并附加'/'(这是Django中一个非常有用的选项)。
In my javascript I had accidentally omitted the trailing '/' in my POST request. This resulted in a redirect (to the correct url). However apparantly POST is automatically converted to GET during a redirect (see e.g. https://*.com/a/10586852/473285).
在我的javascript中,我不小心在POST请求中省略了尾随'/'。这导致重定向(到正确的URL)。但是,在重定向期间,POST会自动转换为GET(例如,请参阅https://*.com/a/10586852/473285)。