我有一个语法错误,上面写着“Uncaught SyntaxError:Unexpected token ILLEGAL”,我认为它位于JavaScript代码的<?php ?>
代码中,但无法弄清楚原因...如果删除代码在<?php ?>
标记中,我没有收到任何错误。我之前删除了错误,但随后错误突然“再次”上升。
所以这是JavaScript函数。我正在调用PHP代码,因为如果出现问题我需要显示错误,并且正在从PHP文件中调用javascript函数。我在这个PHP文件中需要PHP文件。
function visErrorFraaLastOppSjekk() {
document.getElementById("errorLastOpp").innerHTML = "Filnamnet " + "<strong>" + "<?php echo substr($_FILES['file']['name'],0,50) ?>" + "</strong>" + "eksisterer allereide.<br>" + "Gje bilete eit anna namn, eller<br>" + "velg eit anna bilete og prøv igjen.";
}
// Denne funksjonen er for last_opp_sjekk.php som tar med denne sida, index_geolocation, og setter inn tekst i error boks for last opp vindauget
function visErrorFraaLastOppOK() {
document.getElementById("errorLastOpp").innerHTML = "Bilete er blitt opplasta.";
document.getElementById("filNamnTabellR").value = "Opplasta_bilete/" + "<?php echo $_FILES['file']['name'] ?>"; // EDIT: FIXED
document.getElementById("namnLastOpp").value = "<?php echo $_FILES['file']['name'] ?>";
document.getElementById("storrelse_kb").value = "<?php echo round($_FILES['file']['size']/1024000, 3) ?>" + " megabyte " + "(<?php echo round($_FILES['file']['size']/1024, 3) ?>" + " kilobyte)";
}
以下是错误代码的图片:
更新
以下是Google Developer Tools中的一些代码:
<script>
// Denne funksjonen er for last_opp_sjekk.php som tar med denne sida, index_geolocation, og setter inn tekst i error boks for last opp vindauget
function visErrorFraaLastOppSjekk() {
document.getElementById("errorLastOpp").innerHTML = "Filnamnet " + "<strong>" + "<br />
//错误代码在上面一行 未捕获的SyntaxError:意外的标记ILLEGAL
(!)注意:未定义索引:位于 103 上的C:\ wamp \ www \ geolocation_for_voss_gymnas \ index_geolocation_admin.php中的文件
调用堆栈
#TimeMemoryFunctionLocation
10.0029204912 {main}().. \ index_geolocation_admin.php : 0
“+”
“+”eksisterer allereide。“+”Gje bilete eit anna namn,eller
“+”velg eit anna bileteogprøvigjen。“;
}
// Denne funksjonen er for last_opp_sjekk.php som tar med denne sida, index_geolocation, og setter inn tekst i error boks for last opp vindauget
function visErrorFraaLastOppOK() {
document.getElementById("errorLastOpp").innerHTML = "Bilete er blitt opplasta.";
document.getElementById("filNamnTabellR").value = "Opplasta_bilete/" + "<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: file in C:\wamp\www\geolocation_for_voss_gymnas\index_geolocation_admin.php on line <i>109</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0029</td><td bgcolor='#eeeeec' align='right'>204912</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\geolocation_for_voss_gymnas\index_geolocation_admin.php' bgcolor='#eeeeec'>..\index_geolocation_admin.php<b>:</b>0</td></tr>
</table></font>
";
document.getElementById("namnLastOpp").value = "<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: file in C:\wamp\www\geolocation_for_voss_gymnas\index_geolocation_admin.php on line <i>110</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0029</td><td bgcolor='#eeeeec' align='right'>204912</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\geolocation_for_voss_gymnas\index_geolocation_admin.php' bgcolor='#eeeeec'>..\index_geolocation_admin.php<b>:</b>0</td></tr>
</table></font>
";
document.getElementById("storrelse_kb").value = "<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: file in C:\wamp\www\geolocation_for_voss_gymnas\index_geolocation_admin.php on line <i>111</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0029</td><td bgcolor='#eeeeec' align='right'>204912</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\geolocation_for_voss_gymnas\index_geolocation_admin.php' bgcolor='#eeeeec'>..\index_geolocation_admin.php<b>:</b>0</td></tr>
</table></font>
0" + " megabyte " + "(<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: file in C:\wamp\www\geolocation_for_voss_gymnas\index_geolocation_admin.php on line <i>111</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0029</td><td bgcolor='#eeeeec' align='right'>204912</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\geolocation_for_voss_gymnas\index_geolocation_admin.php' bgcolor='#eeeeec'>..\index_geolocation_admin.php<b>:</b>0</td></tr>
</table></font>
0" + " kilobyte)";
}
// Denne funksjonen er for last_opp_sjekk.php som tar med denne sida, index_geolocation, og setter inn tekst i error boks for last opp vindauget
function visErrorLastOppSjekkIV() {
document.getElementById("errorLastOpp").innerHTML = "Fila er ikkje valid. Prøv igjen;<br>" + "sjekk filtypa og filstørrelsen.";
}
</script>
答案 0 :(得分:1)
我在下一行中看到了问题:
document.getElementById("filNamnTabellR").value = "Opplasta_bilete/" + <?php echo $_FILES['file']['name'] ?>;
<?php echo $_FILES['file']['name'] ?>
附近缺少引号或应该是:
document.getElementById("filNamnTabellR").value = "Opplasta_bilete/<?php echo $_FILES['file']['name'] ?>";
请注意,要从服务器端打印数据,最好使用json_encode()
功能。
更新:您仍然遇到问题,因为PHP中未定义$_FILES['file']['name']
。服务器端生成一个警告,该警告以多行打印,而JavaScript不支持这种类型的多行字符串文字。您必须在打印前检查$_FILES
数组元素是否存在。
答案 1 :(得分:1)
这一行是罪魁祸首
document.getElementById("filNamnTabellR").value = "Opplasta_bilete/" + <?php echo $_FILES['file']['name'] ?>;
将其替换为
document.getElementById("filNamnTabellR").value = "Opplasta_bilete/" + "<?php echo $_FILES['file']['name'] ?>";
答案 2 :(得分:1)
更改此
"Opplasta_bilete/" + <?php echo $_FILES['file']['name'] ?>;
到
"Opplasta_bilete/" + "<?php echo $_FILES['file']['name'] ?>";
答案 3 :(得分:1)
所有这些新行。您尝试将巨大的数量的文本填充到JavaScript字符串中,而不先对其进行清理。