我尝试在PHP中回显jQuery,但无论我做什么,它都会给我以下错误:
Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ',' or ';' in /var/www/html/login/application/controllers/sellercentral.php on line 309
代码:
echo '<script>
$( document ).ready(function() {
$("#Drafts > tbody:last").append('foreach($this->central as $key2 => $value2) {
'<tr>
<td><a href='. $value2->Token .'>Edit</a></td>
<td class=T id='. $value2- >Token.'>'.htmlentities($value2->Title).'</td>
</tr>
'.}.' );
});
</script>';
答案 0 :(得分:2)
你不能在echo语句中使用foreach!就这样打破它们:
echo '<script>
$( document ).ready(function() {
$("#Drafts > tbody:last").append(';
foreach($this->central as $key2 => $value2) {
echo '<tr>
<td><a href='. $value2->Token .'>Edit</a></td>
<td class=T id='. $value2- >Token.'>'.htmlentities($value2->Title).'</td>
</tr>';
}
echo ');});</script>';
答案 1 :(得分:1)
我认为您应该在echo
循环中使用foreach
。类似的东西:
echo '<script>
$( document ).ready(function() {
$("#Drafts > tbody:last").append(';
foreach($this->central as $key2 => $value2) {
echo '<tr>
<td><a href='. $value2->Token .'>Edit</a></td>
<td class=T id='. $value2- >Token.'>'.htmlentities($value2->Title).'</td>
</tr>';
}
echo ' );
});
</script>';