【问题标题】:SyntaxError: unexpected token: identifierSyntaxError:意外令牌:标识符
【发布时间】:2018-04-20 09:56:34
【问题描述】:

我正在尝试使用 mix 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);      

非常感谢

【问题讨论】:

  • 但是,你的问题是什么?
  • PHP 在哪里?
  • @JonStirling 前两行...一些 php
  • 哪一行有错误?错误来自 PHP 还是 JavaScript?不要在这里乱扔一堆代码,要具体。
  • 这里有一个错误:let Row = "&lt;tr id=''&gt;&lt;td&gt;"links_displayed - 缺少+

标签: javascript php ajax datatable syntax-error


【解决方案1】:

您忘记了 JS no 中的 + 连接?

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

编辑:

并像这样更改 ajax 中的数据行:

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

【讨论】:

  • 另外,'php_datas='+php_datas+'num_links... 应该是 'php_datas='+php_datas+'&amp;num_links...
  • 是的,'&nb_links' 也是如此
  • 我的意思是编辑您的答案并添加此信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-27
  • 2011-11-21
  • 2017-08-05
  • 2021-03-31
  • 2019-04-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多