Javascript 未捕获引用错误';abc&x27;未在jquery中定义

Javascript 未捕获引用错误';abc&x27;未在jquery中定义,javascript,jquery,html,Javascript,Jquery,Html,我有一个带有按钮的html表格。当单击按钮时,我调用ajquery函数,该函数将调用我的后端服务 Html页面行创建如下 !DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous"> </script> <style> table, th, td { borde

我有一个带有按钮的html表格。当单击按钮时,我调用ajquery函数,该函数将调用我的后端服务

Html页面行创建如下

!DOCTYPE html>
<html>
<head> 
<script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous">
</script>
<style>
table, th, td {
    border: 1px solid black;
}
</style>
<meta charset="UTF-8">
<title>Clients</title>
</head>
<body>
<table style="width:100%" id="clients_data">
<caption>Clients</caption>
  <tr>
    <th>Clients</th>
    <th>Number of Sites</th> 
    <th>Reset the Processing</th> 
  </tr>
  </table>

<!-- --Java script Functions  -->

<script>
function loadCustomers() {
    $.ajax({
        type: 'GET',
        url: 'http://localhost:8080/cache/getCustomers',
        dataType: 'json',
        success: function(data) {
            var rows = [];
            $.each(data,function(id,value) {
                rows.push('<tr><td><a href="clientSiteInfo.html?client='+id+'">'+id+'</td><td>'+value+'</td><td><button type="button" onclick="reset('+id+')">Reset</td></tr>');
            });
            $('table').append(rows.join(''));
        }
    });
};


function reset(id) {
    alert(id)
    $.ajax({
        type: 'GET',
        url: 'http://localhost:8080/cache/reset?clientName='+id,
        success: function(data) {
          alert("Reset success")
        }
    });
};

window.onload = loadCustomers;
</script>
</body>
</html>
当我尝试单击按钮时,我希望它必须将“id”值传递给我的reset()函数

当点击按钮我得到

 ReferenceError: testClient is not defined
    at HTMLButtonElement.onclick ((index):1)
onclick @ (index):1

我在这里做错了什么?

创建行时:

// This is your code
$.each(data,function(id,value) {
  rows.push('<tr><td><a href="clientSiteInfo.html?client='+id+'">'+id+'</td><td>'+value+'</td><td><button type="button" onclick="reset('+id+')">Reset</td></tr>');
});
您希望它看起来像这样:

<button type="button" onclick="reset(testClient)">
<button type="button" onclick="reset('testClient')">

没有这些额外的引号,就不是传递字符串,而是传递变量的值(从未定义)

解决方案是将这些引号添加到HTML模板中:

$.each(data,function(id,value) {
  rows.push('<tr><td><a href="clientSiteInfo.html?client='+id+'">'+id+'</td><td>'+value+'</td><td><button type="button" onclick="reset(\''+id+'\')">Reset</td></tr>');
});
$。每个(数据、函数(id、值){
行。推送(“”+id+“”+value+'Reset');
});

问题代码的关闭位置是哪里?能否显示引用testClient的代码部分?这就是您遇到错误的地方。显示的代码中没有任何内容与
testClient
有关,谢谢您的帮助。理解我的错误。
$.each(data,function(id,value) {
  rows.push('<tr><td><a href="clientSiteInfo.html?client='+id+'">'+id+'</td><td>'+value+'</td><td><button type="button" onclick="reset(\''+id+'\')">Reset</td></tr>');
});