简体   繁体   English

参数列表ERROR ON JS后未捕获到的SyntaxError:缺少)

[英]Uncaught SyntaxError: missing ) after argument list ERROR ON JS

I'm building a table who have a button. 我正在建立一个有按钮的桌子。 When the user click this button the stat of row changes, in the table this represents a field with 0 or 1. Fine i'd made the button but i get an error in some rows, the error is Uncaught SyntaxError: missing ) after argument list, and i get very confused because the code works on like 80% of the time. 当用户单击此按钮时,行的状态发生变化,在表中该字段代表具有0或1的字段。很好,我做了按钮,但在某些行中遇到错误,错误是参数后出现Uncaught SyntaxError:missing)列表,我非常困惑,因为代码在80%的时间内都可以正常工作。

The problem wasn't with the database because i'd already searched for some field with problems. 问题不在于数据库,因为我已经在搜索某些有问题的字段。

function enviaAssociado(CTITULAR) {
    if (CTITULAR) {
        $("#CTITULAR").remove();
        $.ajax({
            url: 'php_action/enviaAssociado.php',
            type: 'post',
            data: {
                CTITULAR: CTITULAR
            },
            success: function() {
                manageTable.ajax.reload();
                //$("#CTITULAR").val(response.CTITULAR);
            }
        });
    }
    manageTable.ajax.reload();
}

PHP 的PHP

` `

$CTITULAR = $_POST['CTITULAR'];


$sql = "UPDATE importsmiles4e.tb_conv
SET    STAT = CASE
     WHEN  STAT = 1 THEN 0
     WHEN  STAT = 0 THEN 1
     ELSE STAT
   END
WHERE  substring(CTITULAR,2,6) = '$CTITULAR'
";
$query = $connect->query($sql);

$CTITULAR = $_POST['CTITULAR'];


$sql = "UPDATE importsmiles4e.tb_conv3
SET    STAT = CASE
     WHEN  STAT = 1 THEN 0
     WHEN  STAT = 0 THEN 1
     ELSE STAT
   END
WHERE  substring(CTITULAR,2,6) = '$CTITULAR'";
$query = $connect->query($sql);


// close the database connection
$connect->close();

echo json_encode($sql);

` `

The Table 桌子

while ($row = $query->fetch_assoc()) {

$active = '';

if($row['EMAIL'] != '') {
        $active = '<label class="label label-success">Cadastrado</label>';
    } else {
        $active = '<label class="label label-danger">Cadastrar</label>'; 
    }


$botao = '<a type="button" class="btn btn-default" onclick="enviaAssociado('.$row['CTITULAR'].') ">Alterar</a>';

$status = '';

if($row['STAT'] == '0'){
    $status ='<label class="label label-warning">Não</label>';  
}else{
    $status ='<label class="label label-success">Sim</label>';
}

$output['data'][] = array(
    $row['NOME'],
    $row['CPF'],
    $row['CEPRES'],
    $row['NROPROPOSTA'],
    $row['DTADMISSAO'],
    $row['DEPENDENTES'],
    $row['VLSMENS'],
    $status,
    $botao,
);

https://i.stack.imgur.com/KnD7w.png => error Log https://i.stack.imgur.com/KnD7w.png =>错误日志

https://i.stack.imgur.com/MhsDh.png => Return when error https://i.stack.imgur.com/MhsDh.png =>错误返回

The return when success is the same the only change is the value key and i've already check if the values are broken. 成功相同时返回的唯一值就是值键,我已经检查了值是否损坏。

The problem is buried away in one of your screenshots: 问题被隐藏在您的其中一个屏幕截图中:

enviaAssociado(0516542.00)

That leading 0 combined with the fact that there are no 8 or 9 digits in it (yes, really ) makes that a legacy octal integer literal in loose mode. 前导0加上其中没有89位的事实(是的, 实际上是 )使得传统的八进制整数文字处于松散模式。 Since it's an integer literal, it can't have a decimal point, so as of the . 由于它是整数文字,因此不能有小数点,因此. it's a syntax error. 这是语法错误。

If that's meant to be a number, have your PHP code strip any leading 0 s from the number. 如果这是一个数字,请让您的PHP代码删除该数字中的前导0 If it's meant to be a string, have your PHP code output it in quotes. 如果是字符串,则将您的PHP代码用引号引起来。

If you output data to JavaScript code from PHP, you're usually best off doing so via json_encode . 如果从PHP将数据输出到JavaScript代码,通常最好通过json_encode这样做。 If you're doing it within an attribute (which is not best practice), you also want htmlspecialchars . 如果要在属性中执行此操作(这不是最佳做法),则还需要htmlspecialchars So: 所以:

$botao = '<a type="button" class="btn btn-default" onclick="enviaAssociado('.htmlspecialchars(json_encode($row['CTITULAR'])).') ">Alterar</a>';

Sometimes, the number will contain an 8 or a 9 and so it'll work (that's why the example you gave in a deleted comment on this answer, 0655178.00 , worked). 有时,数字将包含89 ,因此它将起作用(这就是为什么您在此答案中删除了注释的示例0655178.00起作用的原因)。 This works in loose mode, for instance: 这可以在松散模式下工作,例如:

enviaAssociado(0655178.00)

Notice the 8 . 注意8 (A 9 would do the same thing.) It works because the 8 is in the part of the number prior to the . (A 9会做同样的事情。)之所以有效,是因为8在数字之前的部分. , so the JavaScript parser knows that it's not a legacy octal integer literal, instead it's a (try not to laugh here) non-octal decimal integer literal , which is a specific kind of a decimal integer literal , which means it can be the first part of a decimal literal , so the . ,因此JavaScript解析器知道它不是传统的八进制整数文字,而是( 尝试的) 非八进制整数文字 ,这是一种特殊的十进制整数文字 ,这意味着它可以是第一个十进制文字的一部分,所以. isn't a syntax error. 不是语法错误。 This is one of JavaScript's deep dark corners. 这是JavaScript的深深黑角之一。 (And a good reason to use strict mode, which disallows non-octal decimal integer literals.) (这也是使用严格模式的充分理由,严格模式不允许使用非八进制十进制整数文字。)

But this is just a specific case of where the real problem is not outputting from PHP to JavaScript code correctly (and not properly escaping something being put in an HTML context, specifically in this case an attribute). 但这只是一个特殊的情况,即真正的问题没有正确地从PHP输出到JavaScript代码(并且没有正确地转义放置在HTML上下文中的某些内容,在这种情况下特别是属性)。 So although this legacy octal integer literal thing is a deep dark corner of JavaScript, that's not the real issue. 因此,尽管这种传统的八进制整数文字内容是JavaScript的一个深深黑角,但这并不是真正的问题。 The real issue is ensuring you encode things properly when outputting from PHP to JavaScript like that, via json_encode (and in this case, htmlspecialchars ). 真正的问题是,当通过json_encode (在本例中为htmlspecialchars )从PHP输出到JavaScript时,确保对事情进行正确编码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 参数列表后未捕获到的SyntaxError:缺少)-Forloop JS - Uncaught SyntaxError: missing ) after argument list - Forloop JS app.js:未捕获的SyntaxError:参数列表后缺少) - app.js: Uncaught SyntaxError: missing ) after argument list 参数列表后未捕获到的SyntaxError:缺少)(调用js函数时) - Uncaught SyntaxError: missing ) after argument list (while calling a js function) cart.js:6 Uncaught SyntaxError: missing ) 在参数列表之后 - cart.js:6 Uncaught SyntaxError: missing ) after argument list 参数列表后的String()函数错误-未捕获的SyntaxError:缺少) - String() Function error - Uncaught SyntaxError: missing ) after argument list 参数列表javascript错误后未捕获到的SyntaxError:缺少) - Uncaught SyntaxError: missing ) after argument list javascript error 我的错误在哪里? 参数列表后未捕获到的SyntaxError:缺少) - Wheres my error? Uncaught SyntaxError: missing ) after argument list Javascript错误;参数列表后面的Uncaught SyntaxError:missing) - Javascript error; Uncaught SyntaxError: missing ) after argument list 参数列表后出现错误 Ajax、Jquery Uncaught SyntaxError: missing ) - Error Ajax , Jquery Uncaught SyntaxError: missing ) after argument list 执行以下代码时,在 JS 中出现错误:“未捕获的语法错误:在参数列表后丢失)” - getting error in JS as :"Uncaught SyntaxError: missing ) after argument list" while executing below code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM