I’m getting an unexpected identifier error with this line of code: var player[data[x].split("|",1)] = data[x].split("|")[1];
The response data is in this format:
Mike Trout|0\nRyan Braun|0\n...
Here is the full JS function:
function updateChance(round, pickNumber)
{
$.ajax({
type: "GET",
data: {round: round, pickNumber: pickNumber},
url: "./lib/updatechance.php",
dataType: "html",
async: false,
success: function(response)
{
var data = response.split("\n");
for (var x=0; data.length; x++)
{
var player[data[x].split("|",1)] = data[x].split("|")[1];
}
for (var r = 1; r < $('#battersTable').rows.length; r++){
//do something with player
}
}
});
}
Look what you did here
and
another issue, you have
varwith the bracket notation, not going to happen.And the for loop is missing a check so that is going to run infinite.
Why are you splitting twice? Twice the effort, do it once
If
playeris not defined globally, you will need to define it before the loop.