(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:
$("#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开发者_Go百科 is a post request. Does anyone knows why it happens?
might be related to this ticket: http://bugs.jquery.com/ticket/8084 the quick fix is:
jQuery.ajaxSetup({ jsonp: null, jsonpCallback: null});
before doing ajax calls
check for hidden redirects
in my case I am using Django, where, in general, all URL's end with '/'
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).
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://stackoverflow.com/a/10586852/473285).
精彩评论