-1

我有一个语法错误,上面写着“Uncaught SyntaxError: Unexpected token ILLEGAL”,我认为它在<?php ?>JavaScript 代码中的代码中,但无法弄清楚为什么......如果我删除标签中的<?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 />

// 错误代码在上面一行 Uncaught SyntaxError: Unexpected token ILLEGAL

( ! ) 注意:未定义索引:C:\wamp\www\geolocation_for_voss_gymnas\index_geolocation_admin.php 中的文件在第103行 调用堆栈#TimeMemoryFunctionLocation 10.0029204912{main}( )..\index_geolocation_admin.php : 0 " + "
" + "eksisterer allereide。” + “Gje bilete eit anna namn, eller
” + “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/" + "<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>
4

4 回答 4

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()函数。


更新:您仍然有问题,因为$_FILES['file']['name']在 PHP 中未定义。服务器端生成一个警告,它分几行打印,而 JavaScript 不支持这种类型的多行字符串文字。您必须在打印之前检查$_FILES数组元素是否存在。

于 2013-04-03T10:02:49.173 回答
1

这条线是罪魁祸首

document.getElementById("filNamnTabellR").value = "Opplasta_bilete/" + <?php echo $_FILES['file']['name'] ?>;

将其替换为

document.getElementById("filNamnTabellR").value = "Opplasta_bilete/" + "<?php echo $_FILES['file']['name'] ?>";
于 2013-04-03T10:03:43.963 回答
1

改变这个

"Opplasta_bilete/" + <?php echo $_FILES['file']['name'] ?>;

"Opplasta_bilete/" + "<?php echo $_FILES['file']['name'] ?>";
于 2013-04-03T10:04:09.547 回答
1

都是那些换行符。您正在尝试将大量文本塞入 JavaScript 字符串,而无需先对其进行清理。

于 2013-04-03T10:12:22.513 回答