I have a fairly simple ajax call built on jQuery. It works perfectly in IE9, Firefox latest and Chrome latest (so I’m pretty certain the page which the AJAX call is posting to is fine) but on IE8 (not tried IE7) it fails.
The jQuery code is:
$('.to-step-2').click(function(){
var d = new Date();
var roomShape;
blnError = false;
$.ajax({
url: '/base/RoomBuilder/GetRoomShape.aspx?_='+d.getTime(),
async: false,
type: 'post',
cache: false,
dataType: 'html',
success: function(data){
if(data.substring(0,5) == 'Error'){
alert('Please select a room shape to continue');
blnError = true;
}else{
roomShape = data;
}
},
error: function(jqXHR, textStatus, errorThrown){
alert('Error 6: jqXHR = ' + jqXHR + '\ntextStatus = ' + textStatus + '\nerrorThrown = ' + errorThrown);
blnError = true;
}
});
if (blnError == true){
return false;
}
The error, which is thrown only in IE8 is reading:
Error 6: jqXHR = [object Object]
textStatus = error
errorThrown = Length Required
I’ve seen a few other posts about similar things, but adding the timestamp and cache:false to prevent caching seem to be quite common solutions, but still not working for me 🙁
Can anyone see why this is happening and suggest a fix?
You’re getting a 411 response from your service:
This is because jQuery does not set the content-length header when posting if there is no data. This is a security requirement when posting to IIS:
Simply setting the data parameter to an empty objects seems the simplest workaround: