Reputation: 41
So this function works in all other browsers except IE. I only have access to IE 8 so can't say if newer versions work or not. I don't have access to the PHP or how it's calling the SQL DB, so I can't say for sure it's the javascript. The alert never gets triggered in IE.
$.post( 'http://foo/geo/getGeoResultsByGeoId.php', {geoId: 1}, function(data){
alert('inside');
var DBinfo = $.parseJSON(data);
if(DBinfo.data.length == sites.length) {
for (var i=0; i<sites.length; i++) {
sites[i].votesUp = Number(DBinfo.data[i].votesUp);
sites[i].votesDown = Number(DBinfo.data[i].votesDown);
sites[i].mag = getMagnitude(Number(DBinfo.data[i].votesUp), Number(DBinfo.data[i].votesDown));
createGraph(sites[i]);
}
setMarkers(map, sites);
}
});
Upvotes: 3
Views: 2048
Reputation: 1283
Put this line within your HTML just after the <head
> tag starts
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
It will work for IE8+
.
Along with this, do not forget to mention the data type in your $.post
request. You can do this as
$.post(url,
function(){
//your content here
},'dataType')
.fail(function(jqXHR,status)
{
});
dataType can be xml
, json
, text
, or jsonp
or a combination of datatypes. So, choose as per your datatype and it'll work fine. It worked for me at least, don't know if I'm wrong?
Upvotes: 1
Reputation: 5050
How about something like this instead if your return data is JSON and your making a cross domain request:
$.ajax({
url: 'http://fooURL/getGeoResultsByGeoId.php?callback=?',
data : {geoId: 1},
dataType : 'JSONP',
success: function(data) {
DBinfo = data;
alert('inside');
if(DBinfo.data.length == sites.length) {
for (var i=0; i<sites.length; i++) {
sites[i].votesUp = Number(DBinfo.data[i].votesUp);
sites[i].votesDown = Number(DBinfo.data[i].votesDown);
sites[i].mag = getMagnitude(Number(DBinfo.data[i].votesUp), Number(DBinfo.data[i].votesDown));
createGraph(sites[i]);
}
setMarkers(map, sites);
}
},
type : 'POST'
});
Upvotes: 0
Reputation: 1498
I expect the issue is the timing of the two different success callbacks. This should work:
$.post( 'http://fooURL/getGeoResultsByGeoId.php', {geoId: 1}, function(data){
alert('inside');
var DBinfo = $.parseJSON(data);
if(DBinfo.data.length == sites.length) {
for (var i=0; i<sites.length; i++) {
sites[i].votesUp = Number(DBinfo.data[i].votesUp);
sites[i].votesDown = Number(DBinfo.data[i].votesDown);
sites[i].mag = getMagnitude(Number(DBinfo.data[i].votesUp), Number(DBinfo.data[i].votesDown));
createGraph(sites[i]);
}
setMarkers(map, sites);
}
});
Upvotes: 0