带变量的Ajax函数

I've got a table and fields with "onclick" option:

<td class="name" onclick="ajax_update_entries('<?php echo $field['Player']['name']; ?>')">

It calls function:

function ajax_update_entries(player_name)
  {
  $.post('http://mysite.com/entries/get_entries/' + player_name, function(data)
    {
    $('#gameText').html(data);
    });
  setTimeout('ajax_update_entries(player_name)', 30000);
  }

What it does very good is going to requested page after click on the table field. What it does very wrong, it doesn't recognize "player_name" parameter in setTimeout which should refresh it. In the Opera console it returns:

Uncaught exception: ReferenceError: Undefined variable: player_name

and IE says there's no definition of 'player_name'.

But on the other hand, if I go with:

setTimeout('ajax_update_entries("Michael Jordan")', 30000);

it works and will refresh the page with parameter: Michael Jordan.

So my question is: what's wrong with this script? I mean, why is the variable player_name suddenly forgotten? How to fix it?

You need this instead:

setTimeout(function() {
    ajax_update_entries(player_name);
}, 30000);

The variable was not forgotten, the problem is that you were passing the function call as a string to setTimeout. What happens then, is that it goes through eval (which is not good, by the way), without its original context, so the javascript interpreter does not know what to pass. Hence the error.