Why ajax call does not work on IE7 - javascript

I am developing an app for a company i work for but this ajax call only works on IE9+, FF, Chrome . I've been reading around without much luck.
Here is the code i have.It is pretty simple:
var request_getShoppingCart = $.ajax({
url:"classes/sCart.php?action=getItems",
cache: false,
});
request_getShoppingCart.done(function(Data) {
$('#shoppingCart').html(Data);
});
Any help is appreciated

IE fails with trailing comma.
var request_getShoppingCart = $.ajax({
url:"classes/sCart.php?action=getItems",
cache: false //remove comma here
});
request_getShoppingCart.done(function(Data) {
$('#shoppingCart').html(Data);
});
Also read
jQuery .ajax method in IE7 & IE6 not working but working fine in Firefox
Does Internet Explorer 9 choke on extra commas at the end of array and object literals?

Related

jQuery Script Not Running in IE7

The following code works fine in every other browser except IE7. In fact, with this enabled on the page no scripts will work until I have commented it out.
$(document).ready(function () {
var pathname = $(location).attr('href');
if(pathname.indexOf('sess') === -1){
var path = pathname;
}else{
var path = pathname.replace(/sess[^&]*&?/, "");
}
$.ajax({
type: "POST",
url: "ajax/save_page.php",
data: 'last_page='+path
});
});
I have checked for errant commas and can't find any. If I pass a literal value through the Ajax call and comment out the rest of the function everything begins to work as it should but I need the whole function to work.
Ok, I'm beginning to realise that it isn't going to work on IE7 but I need the script to carry on working as it is without excluding IE7 users completely so I used..
if(navigator.appVersion.indexOf("MSIE 7.")!=-1)
to determine if the browser is IE7 and if so exclude that bit of script. Hopefully the user will be able to persuade their admin to upgrade them to a different browser when they realise that it isn't working as well as it could.
But, for the record, I agree that in an ideal world we shouldn't be supporting IE7 etc but in the real world a lot of people still use it and a lot can't do anything about it. I work within the medical and dental industries and a lot of hospitals etc (about 50%) are still using XP with IE7 with no immediate plans for upgrading despite knowing that XP is no longer supported by Microsoft.
Revision to solution
Ok, I have revised my solution, I am using php sessions now for passing around the sess variable that was previously in the url so I no longer have to try and take it out of the url whilst leaving the rest of the params intact.
So now I am using
var path = window.location.href;
$.ajax({
type: "POST",
url: "ajax/save_page.php",
data: 'last_page='+path
});
Which works fine in all of the browsers I am testing it in including IE7

AJAX Call is not working in IE 11

My AJAX Call is working fine in all browsers including IE 8,9,10,11 in my Windows 8 machine
But the same code is not working in my friend's machine who has windows 7 and IE 11 installed. Though the same code is working on his other browsers i.e. Firfox, Chrome etc.
My AJAX call is as below
str = "type=checkloginstatus";
$.ajax({
type: "POST",
dataType: "json",
url: "random.php?"+$.now(),
cache : false,
data: str
}).done(function( data ) {
console.log(data);
});
Can anyone help me please ?
Thanks in advance !
I have same problem. Windows 7 and IE 11 is a bad combination. When I run my AJAX (called ajaxB.asp from the url line in IE11 it returns data. However if I run it from within my html page it returns NOTHING!
Code:
function winkeltonen(dm)
{
$.get(
"ajax/ajaxB.asp",
{stand: dm},
function (data) {
if (data == '...') // empty
{
$('#DYNdeel2').hide();
}
else
{
document.getElementById('DYNbal').innerHTML = data;
$('#DYNdeel2').show();
}
});
}
It runs fine in opera and Firefox and all IE's before 11

Need to work around selectSingleNode in IE10

My client has a web app that started throwing errors in IE10. I tracked down the source of the error and it seems IE 10 no longer supports selectSingleNode. Here's the function where it's used:
ScormApi.prototype.setTom = function( tom ) {
this.tom = CreateXmlDocument();
var rootelem = importAllNode( this.tom, this.tomTemplate.documentElement, true );
this.tom.appendChild( rootelem );
// Transforms the tracing of the user in tracking template
// Perform the navigation on all nodes of tom and for each value found
// Sets it to this.tom
rootelem = tom.selectSingleNode('//cmi');
this.parseXML( rootelem, '/' , this, this.setTomParam );
}
It's called with the following code:
var ajxreq = new Ajax.Request(
this.baseurl+'?op=Initialize',
{ method: 'post',
asynchronous:false,
postBody: strSoap,
requestHeaders: {
'Man':"POST " + this.baseurl + " HTTP/1.1",
'Host':this.host,
"Content-type":"text/xml; charset=utf-8",
"SOAPAction":this.serviceid + "Initialize",
"X-Signature":playerConfig.auth_request
}
});
if( ajxreq.transport.status == 200 ) {
try {
this.setTom( ajxreq.transport.responseXML );
}
}
I found suggestions to change the response type to msxml-document, use querySelector or use jQuery's find function, but I can't piece together how to actually implement it in this prototype framework. Any assistance would be greatly appreciated.
As for http://doogalbellend.blogspot.fr/2012/04/cross-browser-selectsinglenode-for-xml.html
Update – This no longer works in IE10, since selectSingleNode has been removed from the XML document returned from AJAX calls. This can be worked around by setting the response type of the XmlHttpRequest, like so :
xhr.responseType = 'msxml-document';
Modifying your request by adding responseType: 'msxml-document' in the options should work.
Note, this solution only works if you don't need features from IE 10. But if you have a site that worked fine until IE 10 came along and you just want it to work again, I found this other answer on IE10 javascript access xml element issue
Basically you just put in a meta tag to tell IE 10 to treat your site as if it is IE9 and it works again.
In PHP, if you want to only put the tag in if it's IE10, you can do this:
$isIE10 = (bool) preg_match('/(?i)msie [10]/',$_SERVER['HTTP_USER_AGENT']);
if ($isIE10) echo '<meta http-equiv="X-UA-Compatible" content="IE=9" />';

Cannot access document's title element with jQuery (IE 8)

I'm seeing this issue in Internet Explorer 8, but not in Safari or Firefox. So far, I have not tested in other IE versions.
I am developing my own jQuery plugin and, for this question, I've stripped it down to the two relevant lines.
In IE 8, using the code below, $('title').text() does not do anything. docTitle is blank because title is blank, as if the jQuery selector for <title>, $('title') is not working. (Again, AFAIK, this is just in IE 8)
(function ($) {
$.fn.myPlugin = function (options) {
var title = $('title').text(),
docTitle = escape(title);
};
})(jQuery);
http://jsfiddle.net/sparky672/YMBQ2/
However, using the plain JavaScript code below, document.title is working fine in everything including IE 8...
(function ($) {
$.fn.myPlugin = function (options) {
var docTitle = escape(document.title);
};
})(jQuery);
EDIT:
It does not matter that this code is inside a plugin.
Same result in IE 8 with this...
$(document).ready(function () {
var title = $('title').text();
alert(title);
});
Just to clarify, I am not insisting on using this. In fact, I fixed my plugin by simply using document.title instead. If it wasn't clear initially, I'm just asking why this does not work in IE 8.
Can anyone explain why, or what stupid mistake I may have made here?
EDIT 2:
Here are some jQuery Bug reports on this issue
http://bugs.jquery.com/ticket/7025
http://bugs.jquery.com/ticket/5881
http://bugs.jquery.com/ticket/2755
And dozens of others reporting the same thing. The official response is to state, "document.title is the only reliable cross-browser way and should be used instead" and the Ticket is closed. So there you go.
I guess jQuery iterates over all TextNodes and concatenates its nodeValue. IE stores this value differently than other browsers.
var title = document.getElementsByTagName('title')[ 0 ];
title.firstChild // This would be the Text-Object with the characterdata of the title
// Firefox: [object Text]
// IE: null
This should be the reason you cannot get the textContent with jQuery.text(). title.text seems to be cross browser comp. I only tested it in IE 7 and Firefox 3.6 but you can check the other browser if you like. But why not using document.title?
try using $('title').html() which should work in all browsers

Jquery ajax() call fails in IE8

I have the following code for submitting data using ajax from forms of class ajax. this works perfectly in Firefox, Safari and Chrome but fails in IE.
ajax: function() {
$('form.ajax').live('submit', function() {
var form_ajax = $(this);
$.ajax({
url: form_ajax.attr('action'),
data: form_ajax.serialize(),
type: form_ajax.attr('method'),
dataType: 'script',
beforeSend: function(xhr) {
$('#ajax-bid-new .ajax-form-error, #ajax-bid-new .ajax-form-success').remove();
form_ajax.slideUp();
}
});
return false;
});
Please help - I am stuck here for past 2 days. I am returning a Javascript file from server to be evaluated inside browser. This works as expected in Firefox, Chrome and Safari, but IE receives it as a file and opens up the file download dialog.
What can I do in IE to make this work? I tried by dropping the following code in my application.js file (I'm doing a rails project btw)
// public/javascripts/application.js
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})
I get the same behavior from IE even after writing the ajaxSetup block like above.
Looks like live doesn't work with submit in IE. Have you tried using a normal submit instead:
$('form.ajax').submit(function() {
To catch live form submit events in IE, instead of:
$("form").live("submit", function() { ... });
to
var submitHandler = function() { ... };
$("body").children().each(function() {
$("form", this).live("submit", submitHandler);
})
Point to be noted
IE caches AJAX requests really aggressively (more so than Firefox, anyway). You need to set the Cache-Control headers in the response appropriately if this is not right for your site.
change your content type, last time i fixed similar problem by changing content-type from application/json; charset=utf8 to just plain application/json
jQueries' bind and live behaviours along with the liveQuery plugin
LiveQuery plugin solved the problem http://github.com/brandonaaron/livequery

Categories

Resources