Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何打印发送表单的结果消息';使用Fetch和Aurelia获取数据_Javascript_Fetch_Aurelia - Fatal编程技术网

Javascript 如何打印发送表单的结果消息';使用Fetch和Aurelia获取数据

Javascript 如何打印发送表单的结果消息';使用Fetch和Aurelia获取数据,javascript,fetch,aurelia,Javascript,Fetch,Aurelia,当我尝试在Aurelia中使用fetch发布表单数据并在同一网页上打印消息(如果成功,${resultMessage}),我收到一个错误“Unhandled rejection TypeError:无法将属性'resultMessage'设置为undefined” this.resultMessage=“新增新书” 在函数上下文中,此是函数,而不是类。相反,请使用箭头函数表示法,如下所示: .then(data => { if(data.id) {

当我尝试在Aurelia中使用fetch发布表单数据并在同一网页上打印消息(如果成功,${resultMessage}),我收到一个错误“Unhandled rejection TypeError:无法将属性'resultMessage'设置为undefined”


this.resultMessage=“新增新书”
函数
上下文中,此
是函数,而不是类。相反,请使用箭头函数表示法,如下所示:

.then(data => {
          if(data.id) {
             console.log(JSON.stringify(data));
             this.resultMessage = "New book added"; 
        })

现在
这个
应该是类。

这个
函数
上下文中是函数,而不是类。相反,请使用箭头函数表示法,如下所示:

.then(data => {
          if(data.id) {
             console.log(JSON.stringify(data));
             this.resultMessage = "New book added"; 
        })
现在
这个
应该是类

{
  "id": "2",
  "errors": []
}
.then(data => {
          if(data.id) {
             console.log(JSON.stringify(data));
             this.resultMessage = "New book added"; 
        })