Ghandhikus
Ghandhikus

Reputation: 841

jquery problem with code

This code

   function get_players()
{
    $.ajax({   
    type:   "POST",
    url:    "get_players.php",   
    dataType: "html",  
    success:  function(data) {
        var str = data;
                var chars = str.split("<br />");
                var lol = chars.length;
                for(var i = lol; i--; ) {
                    chars[i] = chars[i].split('/');
                    var o = document.getElementById(chars[i][0]);
                    if (!o) {
                        var aimt = i;
                        if (aimt!=chars.length-1 && aimt != 0) {
                            $('#gracze').html('<div id="'+chars[aimt][0]+'" class="char"></div>'+$('#gracze').html());
                        }
                    } else {
                        $('#'+chars[aimt][0]).position.left = chars[aimt][1];
                        $('#'+chars[aimt][0]).position.top = chars[aimt][2];
                    }
                }
        }});
    setTimeout("get_players();", 2500);
}

Outputs me in js console pls hlp :(

Uncaught Syntax error, unrecognized expression: #

Upvotes: -1

Views: 438

Answers (2)

Emmett
Emmett

Reputation: 14327

jQuery throws "uncaught exception: Syntax error, unrecognized expression: #" when you use an empty id selector, for example:

$('#'); //throws: "uncaught exception: Syntax error, unrecognized expression: #"

So, the problem with your pasted snippet is that chars[aimt][0] is returning an empty string, which is causing $('#'+chars[aimt][0]) to throw an exception.

Upvotes: 4

Bjorn
Bjorn

Reputation: 71850

That is not the place where your problem is, there's nothing wrong with the code you pasted. There's probably a missing ' somewhere else in your code above this part and your code is not closing the string properly until it sees the next ', the following character being the # which is a syntax error.

Looking at your updated code I don't see any syntax errors. Did you fix it?

Upvotes: 2

Related Questions