0

I am trying to run a jquery/ajax call that works in IE9, Chrome, FF, Opera However, it fails in IE8 and UE7

The code:

  $.ajax({url:plink,
      success: function(result) {
        ppriser = result.split("**")[1];
        plabels = result.split("**")[2];
        pgrupper = result.split("**")[3];
        priser = ppriser.split("!#");
        labels = plabels.split("!#");
        grupper = pgrupper.split("!#");
        $("td .pricetag").each( function() {
          var slutpris = "999999";
          var slutlabel = "";
          for(i=1;i<priser.length;i++) {
            str = String($(this).attr('group')); 
            grp = String(grupper[i]);
            pos = grp.indexOf(str);
            if(grp==str || pos>=0) {
              j=parseInt(priser[i]);
              k=parseInt(slutpris);
              if(j!=0 && j<k) {
                slutpris = priser[i];
                slutlabel = labels[i];
              }
              if(slutlabel=="") { slutlabel = "fra:"; }
              if(slutpris!="999999") { 
                $(this).html(slutpris);
                $(this).prev('td').html(slutlabel);
              }
              if(slutpris=="999999") {
                $(this).css('display','none');
                $(this).closest('.pris').css('display','none');
              }
            }
          }
        });
      }});

I have tried various combos of: cache:false, type:"POST", type:"GET", data:"HTML", dataType:"HTML", timeout: 10000,

An example of the link plink:

Default.aspx?ID=148&fb=true&mode=-1&groupid=1210405@@SHOP5,1210103@@SHOP5,

The jquery link:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

The ajax script link is placed at the end of the page.

5
  • perhaps the url does not get properly encoded... @ should be encoded to %40. Commented Mar 1, 2013 at 11:48
  • 1
    Do you get any errors in the console on IE7/8? Commented Mar 1, 2013 at 11:48
  • What is content-type for response of the URL "Default.aspx?ID=148&fb=true&mode=-1&groupid=1210405@@SHOP5,1210103@@SHOP5," ? If it is application/json then IE8/7 will not work as expected. It should be text/plain. Commented Mar 1, 2013 at 11:50
  • the content type is HTML, I get no error messages... replacing @@ with %40%40 made no difference Commented Mar 1, 2013 at 12:04
  • Correction Console: SCRIPT438: Object does not support property or method 'indexOf' Commented Mar 1, 2013 at 12:11

1 Answer 1

1

I tried to cast to string in several wasy (as IE 8/7 does not like indexOf on array objects) but to no avail. Thereafter, I found this solution.

  if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(obj, start) {
      for (var i = (start || 0), j = this.length; i < j; i++) {
        if (this[i] === obj) { return i; }
      }
      return -1;
    }
  }

I test if indexOf is supported - and if not the function is created.

Sign up to request clarification or add additional context in comments.

3 Comments

hm, I thought grp would be a string rather than an array... Array.prototype.indexOf support has been added in IE9.
grp should be a string... but I tried both String(var) and var.toString but with no luck. Implementing the above worked...
Both String(var) and var.toString should give you the string representation of an Array. I have no clue what you did wrong there...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.