-1

I am trying to to implement autocomplete.

I have an issue like

Uncaught Error: Syntax error, unrecognized expression:

This is my code.

<script>
$(function(){
    $('.search').keyup(function(e){
        var input = $(this).val();
        $.ajax({
            type: "get",
            url: "class/contact/get_contact_list.php",
            data: {"current_user_id" : window.USER_DATA.USER.id_user, "type" : "verify", "search": input},
            async: true,
            success: function(data){
                var outWords = $.parseJSON(data);
                $('.data_contact').html('');
                $('.data_contact').prepend($(Chat.append_into_contact_list(outWords,'search')));
                // $('.data_contact').prepend('<div>'+input+'_'+outWords.response.length+'</div>'); //Fills the #auto div with the options
                //$('.data_contact').append($(Chat.append_into_contact_list(outWords,'search')).delay(220).fadeTo('slow',1));
                console.log(outWords);
            }

        })
    })
});
</script>

I think it was an error that lies in $('.data_contact').prepend($(Chat.append_into_contact_list(outWords,'search')));.

Can anyone please suggest what's causing the issue?

durron597
  • 31,968
  • 17
  • 99
  • 158
Gasta
  • 35
  • 7
  • 2
    What is the *actual* value of `data`? Chances are it is not as expected. *Don't* use alert; use the console/debugger, and possibly the network monitor. – user2864740 Jul 28 '15 at 03:54
  • 1
    What do you see when you say alert(data) instead of alert(outwords.length)? – Willy Jul 28 '15 at 03:54
  • sorry, i copy old code. i implement like this $('.data_contact').prepend('
    '+input+'_'+outWords.length+'
    '); and outWords is no amount.
    – Gasta Jul 28 '15 at 03:58
  • 1
    That simply means that the object `outWords` doesn't have a `length` property. What is wrong is that you are trying to access a property that does not exist. Don't do that. You can only access properties that exist. – Felix Kling Jul 28 '15 at 04:04
  • Oh, I see. Thank you answer. I will learn even more. – Gasta Jul 28 '15 at 04:11

1 Answers1

0

parseJSON parses a string (which has length) to an Object - which does not necessarily have a length

Jaromanda X
  • 53,868
  • 5
  • 73
  • 87