Ajax request not working in IE with jQuery
We are facing a peculiar problem of ajax request not being send using jquery. Interestingly, it works on IE8 but not on below versions. I have tried (al)most all of the things mentioned in other related posts but no success.
May be I am missing something big here. But IE seems to be creating lots of trouble both from functionality and css dev perspective. :(
Our web app is based on rails.
Any helps/pointers would be great.
Thanks.
jQuery.ajaxSetup({
cache: true,
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
});
$(document).ajaxSend(function(event, request, settings) {
if (typeof(AUTH开发者_运维技巧_TOKEN) == "undefined") return;
if ( settings.type != 'GET' && settings.type != 'get') {
settings.data = settings.data || "";
settings.data = (settings.data ? settings.data + "&" : "")
+ "authenticity_token=" + encodeURIComponent( AUTH_TOKEN );
}
});
$(document).ready(function(){
$(".signup").live('click', function() {
var a_key = $('#f_auths').find('input[name="a_key"]').val();
var a_uid = $('#f_auths').find('input[name="a_uid"]').val();
var a_provider =$('#foreign_auths').find('input[name="a_provider"]').val();
$(this).closest('form').find('input[name="user[provider]"]').val(a_provider);
$(this).closest('form').find('input[name="user[key]"]').val(a_key);
$(this).closest('form').find('input[name="user[uid]"]').val(a_uid);
$.ajax({
url: "/users",
type: 'POST',
data: $(this).closest('form').serialize() ,
beforeSend: function(){
$('#loading').css('display','block');
},
success: function(){
$('loading').css('display','none');
},
});
return false;
});
I had trouble before with this too. In my case, changing the "type" setting in the Ajax call fixed it. I remember another case where my server was actually sending a slightly wrong mimetype back to the client, so double check the content type sent back from your server script. Hope maybe some of that helps.
Install Internet Explorer Developer Toolbar that will help a lot to find out JavaScript problems if you turn back the script debugging checkboxes in options.
Remove the trailing comma (,), after the last parameter (success). It breaks IE 7.
I once had a problem with jQuery and ajax request where IE7 had a problem parsing the '#' character in the url. After getting rid of the # everything worked as expected.
精彩评论