Simple AJAX request using jQuery not working with IE

This is my code that sometimes works and sometimes not.

var resolve_ajax_login=function(){ $.ajaxSetup({cache:false }); var loginvar=$("#inputlogin").attr("value"); var senhavar=$("#inputsenha").attr("value"); $.post("../model/php/login_ajax.php", {login:loginvar, senha:senhavar}, function(responseText){ if (responseText=="ok"){ window.location="areatrab.php"; }else{ $("#inputlogin").attr("value",""); $("#inputsenha").attr("value",""); $("#divmensagem").html("<span style='color:red;font-size:70%;'>"+responseText+"</span>"); } } ); return false; }; 

Ok This is in Portuguese, but I think you get the big picture. Sometimes this works, no problem, but at some other moments (only in IE, no problem in Firefox) it throws a javascript error in my jquery.js (minified) file. The error description is as follows:

The object does not support this property or method: jquerymin.js string 123 character 183 ..

which amounts to ...

 {return new A.XMLHttpRequest} 

somewhere in the middle of the jquery.js file. This seems to be very specific to IE since I did not have such problems in Firefox. This guy obviously had the same problem as mine, but there is no answer yet.

Has anyone else seen this? Thanks at Advance

PS: I am running IE 8

+4
source share
2 answers

This has something to do with the order in which you try to use different types of browsers to create the right kind of XMLHTTP REQUEST object. I will explain this in more detail on the next page:

AJAX mismatch in IE 8?

0
source

Have you tried using the full URL instead of ... / model ...? For example: http://www.mysite.com/model/login_ajax.php

Also, maybe try changing the "xhr" property using the jQuery.ajax method ... something like:

 var loginvar = $("#inputlogin").val(); var senhavar = $("#inputsenha").val(); var ajax_obj = null; var resolve_ajax_login = function() { if(ajax_obj !== null) { try { ajax_obj.abort(); } catch(e) { } } ajax_obj = $.ajax({ type: 'POST', cache: false, url: '../model/php/login_ajax.php', data: {login:loginvar, senha:senhavar}, dataType: 'text', timeout: 7000, success: function(data) { if(response == 'ok') { alert("right on!"); } else { alert("not ok"); return; } }, error: function(req, reqStatus, reqError) { alert("error"); return; }, 'xhr': function() { if(ajax_obj !== null) { return ajax_obj; } if($.browser.msie && $.browser.version.substr(0,1) <= 7) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { return new XMLHttpRequest(); } } }); } 
+1
source

All Articles