I want to log in user within a popup.html. When I am doing by fetch request to my Back-end authenticate , request goes to local popup.html?email=eee@mail.com&password=123, instead of server address http://localhost:4003/api/authenticate
can you help me ?
Here is my popup.html:
<form id="mainForm" class="" novalidate>
<div class="login">
<div class="loginrow"><label>Email:</label></div>
<div class="loginrow"><input type="email" id="email" name="email" value="elshad" /></div>
<div class="loginrow"><label>Password:</label></div>
<div class="loginrow"><input type="password" id="password" name="password" value="pass" /></div>
<div class="loginrow">
<input id="logmein" type="submit" value="Login"/>
<button id="signmeup">SignUp</button>
<button id="forgot">Problems?</button>
</div>
</div>
</form>
This is code in popup.js:
logmein.addEventListener("click", async () => {
console.log("Clicked");
// In your JS :
form = document.getElementById("mainForm");
form.submit(function( event ) {
event.preventDefault();
const formData = new URLSearchParams(new FormData(this));
fetch("http://localhost:4003/api/authenticate",
{ method: 'POST',
headers: { "Accept": "application/json", "Content-Type": "application/json; charset=utf-8" },
//mode : 'same-origin',
mode: "no-cors",
credentials: 'same-origin' ,
body : formData
})
.then(function(response) {
return response.text()
}).then(function(text) {
//text is the server's response
});
});
});