Problem with jquery.ui.autocomplete.js on IE7

前端 未结 3 611
天命终不由人
天命终不由人 2021-01-14 06:09

Here is the code. IE7 spouts an \"\'active.0\' is null or not an object\" error on line 39, which is:

input.trigger(\"activate.autocomplete\", [$.data(active         


        
相关标签:
3条回答
  • 2021-01-14 06:30

    Here is my code that works javascript first:

    $(".student_search").autocomplete("student_search.php", {
                    minChars: 2,
                    cacheLength: 20,
                    matchContains: true,
                    highlightItem: true,
                    parse: function(data) {
                                return $.map(eval(data), function(row) {
                                    return {
                                            data: row,
                                            value: row.studentname, //value being searched for
                                            result: row.studentidnumber //value in text input
                                            }
                                });
                    },
                    formatItem: function(row, i, max, term) {
                        return "<span style='font-size: 110%;'>" + row.studentname + "</span><br/>" + "ID: " + row.studentidnumber + ", " + " Grade: " + row.studentgradenumber;
                                },
                    formatResult: function(row, i, max){
                        return row.studentidnumber;
                    }
            });
    

    });

    Here is the code in the PHP file. It prints a JSON object with the data.

    if(isset($_GET['q'])){
    require_once("php/mysql.connect.php");
    $request = strtolower($_GET['q']);
    $query = mysql_query("SELECT 
                        CONCAT(studentfname, ' ', studentlname, '') 
                            AS studentname, studentidnumber, 
                                CONCAT(studentgradenumber, 'th') 
                                    AS studentgradenumber
                                        FROM studentinfo
                                            WHERE studentlname LIKE '%".$request."%'
                                                OR studentfname LIKE '%".$request."%'
                                                    OR studentidnumber LIKE '%".$request."%'") or die(mysql_error());
    
    $results = array();
    
    $i = 0;
    while($row = mysql_fetch_assoc($query)) //fetch each result using the column name as the array key
    {
      foreach($row as $column=>$val) //loop through each column
      {
        $results[$i][$column] = $val; //build array using incremental row # and column name
      }
      $i++; //increase the row counter
    }       
    print json_encode($results);
    }
    

    The JSON object that is printed is:

    [{"studentname":"Joe Schmo","studentidnumber":"123456","studentgradenumber":"11th"}]
    

    so row.studentname returns Joe Schmo. Where row is the name of the variable in the function and studentname is the name of the key from the JSON object.

    Cheers!

    0 讨论(0)
  • 2021-01-14 06:35

    I had problems with autocompletion of jquery ui version 1.8.9 and IE7. I use 1.8.16 now and it works.

    0 讨论(0)
  • 2021-01-14 06:40

    Check out:

    http://github.com/istruble/jquery-autocomplete/commit/bdc926bd2c18c3ebab4e31463a8ae899fd761316#diff-1

    It is a version of jquery.ui.autocomplete.js with most of the IE 7 issues fixed. I found a few more issues which I listed at the bottom along with how to fix them.

    0 讨论(0)
提交回复
热议问题