javascript 语法错误:意外标记:标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49938967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 08:50:26  来源:igfitidea点击:

SyntaxError: unexpected token: identifier

javascriptphpajaxdatatablesyntax-error

提问by Alexandre Michon

I'm trying to do an ajax request, code below, with mix datatable.js. But i don't find the glue.

我正在尝试使用混合 datatable.js 执行 ajax 请求,代码如下。但是我没有找到胶水。

let php_datas = '<?php echo $_path."|".json_encode($LNG). "|".json_encode($array_uzers)."|".$month ."|".$year."|".$membre."|".$user ."|".$debut_ts."|".$fin_ts."|".$get_payments ."|".json_encode($links_displayed); ?>';
let num_links = '<?php echo ($num_links + $nb_display_links);  ?>';
let nb_display_links = '<?php echo ($nb_links + 500); ?>';
console.log(php_datas);
setTimeout(function(){

    $.ajax({
        url:'lib/ajx_List_link.php',
        type: 'POST',
        data: 'php_datas='+php_datas+'num_links='+num_links+'nb_links='+nb_display_links,

        success: function (jsondatas) {

            let links_displayed = jQuery.parseJSON(jsondatas);

            for(let i = 0; i < links_displayed.length ;i++){

                let table = $('#datatable-example').DataTable();

                        //links_displayed[i]["currency"]

                        let Row = "<tr id=''><td>"links_displayed[i]["checkbox"]"</td></tr>";


                table.row.add(Row).draw(  );
                }
        },
        error: function(){
            alert ('elle est où ma data ?');
        }

    });

}, 5000);      

thanks a lot

多谢

回答by keegzer

You forget the + for concatenation in your JS no ?

你忘记了在你的 JS 中连接的 + 没有?

let Row = "<tr id=''><td>" + links_displayed[i]["checkbox"] + "</td></tr>";

Edit :

编辑 :

Andchange your data line in your ajax like this :

像这样在 ajax 中更改数据行:

data: 'php_datas='+php_datas+'&num_links='+num_links+'&nb_links='+nb_display_links,