Javascript setInterval not working in IE7 and IE8 - javascript

I am using the Javascript setInterval to keep polling the server for any updates and refresh the screen with the response from the server. I need to support >IE7, and other major browsers.
The setInterval function is getting fired in all the browsers except IE7 and IE8.
According to the suggestions I saw in other posts I have tried setting cache:false on the ajax requests as well as wrapping the setInterval call in an anonymous function. But none of the suggestions seem to work.
Following is the code I am using:
$(document).ready(function () {
setInterval(pollForServerUpdates, 30000);
});
function pollForServerUpdates() {
$.ajax({ url: $.url("Home/GetUpdates"),
type: "POST",
cache: false,
success: function (result) {
updateTabelWithCurrentStatus(result);
},
dataType: "json"
});
}
I am not sure if I am missing anything here. Any help is very much appreciated.
Thanks!

I am putting my comments above as the answer to this question. The issue was happening because "class" seems to be a reserved keyword in IE and causing an error. When creating the element, I wrapped the class keyword in quotes and all is well. Thanks Pointy for asking me to look at the console. #Spudley, thanks for the tip, I will be refactoring my code with your suggestion.

Related

jquery ajax callback not working

please helppp :/
I swear to GOD this things was working yesterday pretty well. Just broke today, dont know why.
but the done callback from $.ajax is not firing.
function check() {
$.ajax({
url: "/statistics/setup-Table",
dataType : "json",
success: function(data){
alert("check "+data['total']);
}
}).done(function(){
alert("done");
}).fail(function(){
alert("fail");
}).always(function(){
alert("always");
});
}
i only get one alert >> "check 24"
no alerts from done, fail or always pops up. even for the other $.ajax calls, callback functions are not getting fired.
The url is fine too.
Thanks in advance.
It was the version I was using of Jquery that messed things up. the CDN that is.
Kevin B - thank you much .that really helped.
Thank you to all the rest as well who looked into it for me .
You guys r amazing, i love this community. i hope i can help back as well ..
later guys. :)

How to get Twitter search results in Javascript

I would like to grab a list of the recent appearances of a hashtag, but this seems to be impossible to do in Javascript at the moment. I have seen a lot of code snippets around that read like:
function searchTwitter(query) {
$.ajax({
url: 'http://search.twitter.com/search.json?' + searchTerm,
dataType: 'jsonp',
success: function (data) {
//some code
}
});
}
However, this does not seem to work anymore. If I try to use it, I get an error in the console like so:
XMLHttpRequest cannot load http://search.twitter.com/search.json?q=%23twitter. Origin http://myserver.com is not allowed by Access-Control-Allow-Origin.
The same thing happens if I use $.getJson(). Is there a solution for this? A workaround? It seems as though they changed something and then suddenly no one's client-side code works anymore. I really would like to be able to grab the data using Ajax so I can update my page without having to reload the whole thing.
If I am missing something obvious, please let me know.
You can solve this by configurin apache to
Access-Control-Allow-Origin *
Or for some reasons which i do not understand it worked using jQuery.getJSON();
function searchTwitter(query) {
$.getJSON({
url: 'http://search.twitter.com/search.json?' + searchTerm,
success: function (data) {
//some code
}
});
}
http://api.jquery.com/jQuery.getJSON/

IE8 XHTML returned in jQuery ajax call issue

I'm having an issue I cannot resolve through trying lots of different methods!!
Works in Chrome, FF, IE9 but not IE8 or IE7
Overview
I have a page, that Ajax's in the whole HTML from a local .aspx of which reads a photobucket XML feed puts into an HTML list and returns.
http://custommodsuk.com/Gallery.aspx
I've done it this way so the page ranking isn't penilised by Google speed rankings, as the server would be going off and making the call.
The code
$.ajax({
type: "GET",
url: ajaxURL,
dataType:'html',
success: function (feedHTML) {
var galleryList = $(feedHTML).find('#galleryList').find('.listItem');
var noItems = galleryList.length;
console.log(feedHTML.type);
galleryList.each(function (index) {
...
});
}
});
What I've tried
As you can see the console.log(),
the type is undefined, the feedHTML.length shows no. of characters. And from what I gather is generally treated as a string.
It is the JQuery not being able to turn the response into a jQuery object, and I can't traverse it. Therefore the each won't cycle.
I've seen lots of people with the same/similar issue on SO, but no answers, partly due to crap code examples.
Photobuckets RSS feed is malformed.
<p>CustomModsUK posted a photo</a></p>
This tripped up IE8. If you ever have problems like this in the future, check the validity of the HTML!!!

jQuery-ajax call: async property is not working?

given to certain circumstances, I'm forced to keep page settings (Javascript-values) in the session and it has to be done right before leaving the page (I can't use cookies, since "pageSettings" can become quite large and localStorage is not an option yet ;) ). So this is how I tried it. However it seems that when I call the page directly again, the call of "http://blabla.com/bla" happens asynchronous, even though the async-attribute is set (I don't receive the settings of the previous call, but of the one before):
$jQ(document).ready(function () {
$jQ(window).unload(Main.__setSessionValues);
});
var Main = {
pageSettings: {},
__setSessionValues: function __setSessionValues() {
$jQ.ajax({
type: "POST",
async: false,
url: "http://blabla.com/bla",
data: {
pageSettings: Object.toJSON(Main.pageSettings)
}
});
}
};
Does anyone know what the problem might be?
thanks in advance
The code looks fine. You might try bind('beforeunload', ...) rather than unload, to grab things as early as possible. But of course, if something else also hooks beforeunload and the unload gets cancelled, your call will have been made even though you're still on the page.
Slightly off-topic, but if you can possibly find a different way to do this, I would. Firing off synchronous ajax calls when the user is trying to leave the page is not ideal.

strange behaviour with json object coming from ajax call in safari/webkit

I'm using jquery to make an AJAX POST call to a web service, and getting a JSON object back, which gives me back some html code that i want to append to a div, it works fine in firefox but the problem is that safari doesn't do the appending, here is the example:
$.ajax({
type: "POST",
url: "ConnMgr.asmx/Request",
data: JSON.stringify(objectToSend),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response){
$('#myDiv').empty();
$("#myDiv").append(response.d.htmlSnippet); //this doesn't work on safari but it does on FF
//$("#myDiv").append("<img src=\"image.png"/>")//this works in all browsers
//alert(response.d);//this works in all browsers
}
});
It seems that in safari, jquery doesn't like the idea of using a json object as an argument for append()
I've tried creating a copy of the variable before, inserting a delay, converting the variable to string before passing it, but the results are the same.
Many thanks
did you try response.d.htmlSnippet.ToString()
You mean something like this http://jsbin.com/elapa/ doesn't work for you in safari?
yes i did try using response.d.htmlSnippet.ToString() and it didn't help
finally i did a workaround by composing the htmlsnippet and then taking only one number from the coming JSON object, and this way it worked
safari debugging console didn't report any error
Not to be nitpicky, but isn't this block the same as
success: function(response) {
$('#myDiv').empty();
//this doesn't work on safari but it does on FF
//$("#myDiv").append("<img src=\"image.png"/>")//this works in all browsers
//alert(response.d);//this works in all browsers
$("#myDiv").append(response.d.htmlSnippet);
}
as this block because you can chain method calls in jQuery?
success: function(response) {
$('#myDiv').html(response.d.htmlSnippet);
}
Can you try doing something like this?
$('#myDiv').html( '' + response.d.htmlSnippet );
I don't know if it will work or not...but it's worth a try.
I think your code response.d.htmlSnippet.ToString() might not work.
It should be a lowercase "toString()".
There is a difference in JSON implementation between FF and others that I spotted once - others don't allow weird charactersto be passed. You would have to use entities.
Try seeing for sure what comes back - drop the whole response object to a firebug-alike console and see the content. alerting it might not be enough.

Categories

Resources