我使用的是netbeans php 7.3,似乎无法解决此警告"预期EOF,但找到}"
代码如下。它在一个php文件中。
<script type="text/javascript">
function downloadStats($filename,$album,$type){
$('#downloaddiv').html('<img src="images/ajax-loader.gif" />');
$.ajax({
type: 'POST',
url: 'download.php',
<?php
if($_GET['urltype']=='basketball'){
?>
data: "filename=" + $filename + "&album=" + $album + "&type=" + $type + "&area=source&uploadyear=<?php echo $uploadyear;?>",
<?php
} else {
?>
data: "filename=" + $filename + "&album=" + $album + "&type=" + $type + "&uploadyear=<?php echo $uploadyear;?>",
<?php
}
?>
<?php global $tag; ?>
success: function(msg) {
$('#downloaddiv').html('<b title="Stat available for download. Click HERE to download." ><?php echo $tag['view_013'];?> <?php echo $tag['view_014'];?> <a href="'+msg+'"><?php echo $tag['view_015'];?></a> <?php echo $tag['view_016'];?></b>');
}
}); <=== red circle/exclamation mark here
}
</script>
Netbeans在倒数第二行抛出一个红色圆圈/感叹号});
php文件有600多行,所以为了简单起见,我将代码部分粘贴到一个新文件中,netbeans仍然在同一位置抛出错误});
我编辑了代码,现在就试试这个:
<?php
function downloadStats($filename,$album,$type){
?>
$('#downloaddiv').html('<img src="images/ajax-loader.gif" />');
$.ajax({
type: 'POST',
url: 'download.php',
<?php
if($_GET['urltype']=='basketball') :
?>
data: "filename=" + $filename + "&album=" + $album + "&type=" + $type + "&area=source&uploadyear=<?php echo $uploadyear;?>",
<?php
else :
?>
data: "filename=" + $filename + "&album=" + $album + "&type=" + $type + "&uploadyear=<?php echo $uploadyear;?>",
<?php
endif;
global $tag; ?>
success: function(msg) {
$('#downloaddiv').html('<b title="Stat available for download. Click HERE to download." ><?php echo $tag['view_013'];?> <?php echo $tag['view_014'];?> <a href="'+msg+'"><?php echo $tag['view_015'];?></a> <?php echo $tag['view_016'];?></b>');
}
});
<?php
}
?>
<script type="text/javascript">
<?php echo downloadStats($filename,$album,$type); ?>
</script>
关于关闭和打开php这就是我的意思:
这是有效的,但不是最好的方式:
<?php
endif;
?>
<?php
global $tag; ?>
这是有效的,但要好得多:
<?php
endif;
global $tag; ?>
此外,如果可能不使用全局,请查看有关该url的更多信息:https://stackoverflow.com/a/12446305/1788516
编辑
问题是因为在同一个文件中有javascript和php。有关详细信息,请参阅http://netbeans.org/bugzilla/show_bug.cgi?id=166694针对bug。