aurelia-fetch-clientを使用してjsonデータをサーバーに送信すると、このエラーが発生しました。「TypeError:NetworkErrorでリソースを取得しようとしています。あなたの答えは私にとってとても役に立つと思います。TypeError:リソースをフェッチしようとしたときのNetworkErrorを解決する方法
---> post.html
<template>
<section>
<form role="form" submit.trigger="signup()">
<div class="form-group">
<label for="OrganisationId">OrganisationId</label>
<input type="text" value.bind="organisationId" placeholder="OrganisationId">
</div>
<div >
<label for="OrganisationName">OrganisationName</label>
<input type="OrganisationName" value.bind="organisationName" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Enter</button>
</form>
</section>
</template>
---->これはおそらく、クロスオリジンリソース共有(CORS)に関連している
import 'fetch';
import {HttpClient, json} from 'aurelia-fetch-client';
let httpClient = new HttpClient();
export class signup{
heading1 ="Welome to User";
organisationId ="";
organisationName ="";
signup()
{
alert("calliong");
var myUser1 = { organisationId: this.organisationId, organisationName: this.organisationName }
console.log(myUser1);
httpClient.fetch('http://172.16.0.26:8085/employee-management/rest/employees/addOrganisations', {
method: "POST",
body: JSON.stringify(myUser1)
})
.then(response => response.json())
.then(data => {
console.log(data);
});
}
}