【发布时间】:2020-09-15 05:04:09
【问题描述】:
我有某种无法解决的范围问题。这幅画值一千字。当 OK 或 REJ 按钮调用 reject() 函数时,将 user_id 作为 id 作为参数传递给拒绝函数。
我在 Firefox 中收到 JS 控制台错误:“ReferenceError: BUUS123US163 is not defined”。
奇怪的是,甚至定义了错误,也就是说,它确实列出了所需的唯一 ID。我确实尝试将数据的浅层和深层副本放入一个名为 theUsers 的全局数组中,但它还没有工作。对于我认为是范围问题的问题,我遗漏了什么?
更新: JSON.parse 错误 在reject()函数的.catch子句中
// function getting: JSON.parse error
function reject(id) {
console.log("hey: reject ran... ");
// User Data
const data2 = {
user_id: '',
utility: 'delete'
}
data2.user_id = id;
// // POST : pass user
http.post('http://localhost:9999/Password/empapproval', data2)
.then(data => console.log(data))
.catch(err => console.log(err));
}
// http.post calls the following:
post(url, data) {
console.log("easyHttp is running ...");
return new Promise((resolve, reject) => {
console.log("easyHttp Promise is running ...");
fetch(url, {
method: 'POST',
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify(data)
})
.then(res => res.json())
.then(data => resolve(data))
.catch(err => reject(err));
});
}
【问题讨论】:
-
请将您的代码发布为纯文本,而不是图像。
-
this.id应该是什么?reject()不是方法,它没有this上下文。 -
我认为您需要在
'${}'周围加上引号,因此它不会将您的数据视为变量名。 -
也许
this.id应该是id? -
@DaveAnkin 将其作为答案发布。
标签: javascript arrays json object scope