Jquery / Ajax不适用于Chrome和FireFox,但不适用于IE

时间:2013-04-29 10:39:02

标签: jquery ajax internet-explorer jsonp

当您在文本框中输入时,我的实时代码为http://dev9.edisbest.com/Kataloop.html?id=21 Json结果显示在Chrome和Firefox中。

但它在IE中无效,显示状态:错误&内容:(失败)

<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  <script>
//<![CDATA[

function getcatalog(catalogid,id){

window.location.href="http://www.kataloop.com/search-results/#t2_mgi="+id+"&t2_mfi=-1&t2_mi="+catalogid+"&t2_es=t2_mi";

}
function getprinter(seriesid, id)
{
var printerurl = "http://t2json.tgoservices.com/818746/PrinterSeries/"+seriesid+"/Printers";
    $.ajax({
      cache: false,
      url: printerurl
    }).done(function(data, textStatus, jqXHR){  
      $('#content').show();

$.each(data,function(i,item){

var items = item.Printers.Items;

    for(var a = 0; a < items.length; a++) {


    $("#content2").append('<a class="manufacturer" onclick="getcatalog('+items[a].Id+','+id+');" id="'+items[a].Id+'" style="cursor:pointer;" >'+ items[a].Name + '</a>');
 $("#content1").hide();
 $("#content").hide();
       }

});



    }).fail(function(jqXHR, textStatus) {
      $('#status').html(textStatus);    
      $('#content').html('(failed)');
    });
}


     function getParameter(param) {

var val = document.URL;
var url = val.substr(val.indexOf(param));
var n=url.replace(param+"=","");

        if(n)
        {
        var seriesurl = "http://t2json.tgoservices.com/818746/PrinterManufacturers/21/PrinterSeries";

    $.ajax({
      cache: false,
      url: seriesurl
    }).done(function(data, textStatus, jqXHR) {     

    $('#content').html(JSON.stringify(data));


$.each(data,function(i,item){
    var items = item.PrinterSeries.Items;

    for(var a = 0; a < items.length; a++) {
    var id;

    $("#content1").html('<a class="manufacturer" onclick="getprinter('+items[a].Id+','+n+');" id="'+items[a].Id+'" style="cursor:pointer;" >'+ items[a].Name + '</a>');
       }




});
    }).fail(function(jqXHR, textStatus) {
      $('#status').html(textStatus);    
      $('#content').html('(failed)');
    });
        }

        if(location.pathname.indexOf('/dell/') != -1)
        {

            var printerurl = "http://t2json.tgoservices.com/818746/PrinterManufacturers/1718/Printers";

    $.ajax({
      cache: false,
      url: printerurl
    }).done(function(data, textStatus, jqXHR) {      

      $('#content').show();

$.each(data,function(i,item) {

var items = item.Printers.Items;
    for(var a = 0; a < items.length; a++) {


    $("#content2").append('<a class="manufacturer" onclick="getcatalog('+items[a].Id+','+n+');" id="'+items[a].Id+'" style="cursor:pointer;" >'+ items[a].Name + '</a>');
 $("#content1").hide();
 $("#content").hide();
       }




});



    }).fail(function(jqXHR, textStatus) {
      $('#status').html(textStatus);    
      $('#content').html('(failed)');
    });

        }

        if(location.pathname.indexOf('/kodak/') != -1)
        {

            var printerurl = "http://t2json.tgoservices.com/818746/PrinterManufacturers/944/Printers";

    $.ajax({
      cache: false,
      url: printerurl
    }).done(function(data, textStatus, jqXHR) {      

      $('#content').show();

$.each(data,function(i,item) {

var items = item.Printers.Items;
    for(var a = 0; a < items.length; a++) {


    $("#content2").append('<a class="manufacturer" onclick="getcatalog('+items[a].Id+','+n+');" id="'+items[a].Id+'" style="cursor:pointer;" >'+ items[a].Name + '</a>');
 $("#content1").hide();
 $("#content").hide();
       }




});



    }).fail(function(jqXHR, textStatus) {
      $('#status').html(textStatus);    
      $('#content').html('(failed)');
    });

        }


    if(location.pathname.indexOf('/okidata/') != -1)
        {

            var printerurl = "http://t2json.tgoservices.com/818746/PrinterManufacturers/91/Printers";

    $.ajax({
      cache: false,
      url: printerurl
    }).done(function(data, textStatus, jqXHR) {      
    // $('#status').html(textStatus);
      $('#content').show();

$.each(data,function(i,item) {

var items = item.Printers.Items;
    for(var a = 0; a < items.length; a++) {


    $("#content2").append('<a class="manufacturer" onclick="getcatalog('+items[a].Id+',91);" id="'+items[a].Id+'" style="cursor:pointer;" >'+ items[a].Name + '</a>');
 $("#content1").hide();
 $("#content").hide();
 $("#status").hide();
       }




});



    }).fail(function(jqXHR, textStatus) {
      $('#status').html(textStatus);    
      $('#content').html('(failed)');
    });

        }

        if(location.pathname.indexOf('/pitney-bowes/') != -1)
        {

            var printerurl = "http://t2json.tgoservices.com/818746/PrinterManufacturers/97/Printers";

    $.ajax({
      cache: false,
      url: printerurl
    }).done(function(data, textStatus, jqXHR) {      

      $('#content').show();

$.each(data,function(i,item) {

var items = item.Printers.Items;
    for(var a = 0; a < items.length; a++) {


    $("#content2").append('<a class="manufacturer" onclick="getcatalog('+items[a].Id+','+n+');" id="'+items[a].Id+'" style="cursor:pointer;" >'+ items[a].Name + '</a>');
 $("#content1").hide();
 $("#content").hide();
 $("#status").hide();
       }




});



    }).fail(function(jqXHR, textStatus) {
      $('#status').html(textStatus);    
      $('#content').html('(failed)');
    });

        }    

}
var v = setTimeout('getParameter("id")',3000);    
 //]]>       
    </script> 
    </head>
<body>
  <input id='xhr_url' style='width:600px;' type='text' value='http://t2json.tgoservices.com/818746/PrinterManufacturers'/>

  <fieldset><legend>Time:</legend>
    <div id='time'></div>
  </fieldset>
  <fieldset><legend>Status:</legend>  
    <div id='status'></div>
  </fieldset>
  <fieldset><legend>Content:</legend>

    <div id='content'></div>
    <div id='content1'></div>
    <div id='content2'></div>

  </fieldset>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

尝试定义数据类型

dataType: "json"

尝试从

更改内容类型
application/json; charset=utf8 

只是简单的

application/json.

您还可以向调用添加一些随机数据以避免IE缓存

var d = new Date()
    $.ajax({
        url:"......?_="+d.getTime(), 
....