Jquery post not working in IE 8 or earlier

旧时模样 提交于 2019-12-14 04:25:24

问题


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);
     }
});

回答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?




回答2:


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);
    }
});



回答3:


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' 
});


来源:https://stackoverflow.com/questions/13997857/jquery-post-not-working-in-ie-8-or-earlier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!