Ajax functions with variables
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?
Total Views: 70 Today Views: 0















