3

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);
     }
});
PhearOfRayne
  • 4,990
  • 3
  • 31
  • 44
  • 2
    why do you have 2 success functions? – wirey00 Dec 21 '12 at 22:14
  • as @wirey stated, you don't need .success() if you're using the call back, since the callback is a .success() essentially. choose one or the other. – kennypu Dec 21 '12 at 22:17
  • 1
    @kennypu: Sounds like an answer to me.... – Wesley Murch Dec 21 '12 at 22:19
  • @WesleyMurch I'm not sure whether both functions will run or not, and how it works in different browsers so I won't post that as an answer :) – kennypu Dec 21 '12 at 22:20
  • sorry, that was left over from me trying to debug. Doesn't make any difference in IE whether in success or or not, still broken :( – user1310774 Dec 21 '12 at 22:22
  • If you alert(data) instead of alert('inside'); what do you see? – Mark Schultheiss Dec 21 '12 at 22:33
  • nothing in IE, any other browser I'll get JSON object that's like this but a 100 or more entries {"data":[{"name":"Brian Kelly","votesUp":"3","votesDown":"2"},{"name":"Rich Ellerson","votesUp":"0","votesDown":"0"},{"name":"Bronco Mendenhall","votesUp":"0","votesDown":"0"},{"name":"Ken Niumatalolo","votesUp":"1","votesDown":"0"},{"name":"Jimbo Fisher","votesUp":"0","votesDown":"0"},{"name":"Dabo Swinney","votesUp":"1","votesDown":"2"},{"name":"Dave Doeren","votesUp":"2","votesDown":"0"}]} – user1310774 Dec 21 '12 at 22:43
  • 1
    @user1310774 Is this a cross-domain request? IE doesn't support CORS in the same way modern browsers do. (it requires using a different object to send the request, which is not supported by jQuery.) – Kevin B Dec 21 '12 at 22:48
  • 1
    yes it's a cross-domain request. What's the solution without jQuery? – user1310774 Dec 21 '12 at 23:03
  • Possible duplicate of [jQuery $.post() + IE8](http://stackoverflow.com/q/6845150/1699210) – bummi Aug 26 '13 at 10:41

3 Answers3

1

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?

AJ.
  • 4,526
  • 5
  • 29
  • 41
Sandeep Kumar
  • 1,193
  • 13
  • 14
0

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);
    }
});
Joseph Yancey
  • 1,498
  • 1
  • 9
  • 7
  • sorry, that double success was just left over from me trying basically anything and everything to get it to work. Same issue with everything in one success. – user1310774 Dec 21 '12 at 22:26
0

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' 
});
PhearOfRayne
  • 4,990
  • 3
  • 31
  • 44