Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

cors error in post request resolved

let postel = document.getElementById("post");
let postInputel = document.getElementById("postInput")
let postIdInputel = document.getElementById("postIdInput")
let postNameInputel = document.getElementById("postNameInput")
let postAgeInputel = document.getElementById("postAgeInput")
let postResultel = document.getElementById("postResult")

var formData = {
    id:"",
    name:"",
    age:""
}


postIdInputel.addEventListener("change", function(event) {
    formData.id = event.target.value;
});

postNameInputel.addEventListener("change", function(event) {
    formData.name = event.target.value;
});

postAgeInputel.addEventListener("change", function(event) {
    formData.age = event.target.value;
});

const postMethod = () => {
    let options = {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          'Access-Control-Allow-Origin': 'http://localhost:7000'
        },
        body: JSON.stringify(formData)
      
    };
    console.log(formData)
        let url = postInputel.value;
        console.log(url);

        fetch(url, options)
          .then(function(response) {
            alert("DATA INSERTED SUCESSFULLY");
          })
}


postel.addEventListener("submit", function(event){
    event.preventDefault();
    postMethod();
  });
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to reset count in react 
Javascript :: scroll to list element javascript 
Javascript :: find short number in array javascript 
Javascript :: Comparison Primitive operations Methods 
Javascript :: metodo para objeto donde el segundo le pasa un argumento sera un callback method y pasar al arra.filter 
Javascript :: Pause interval button javascript 
Javascript :: k6 control a live k6 test 
Javascript :: For Anweisung 
Javascript :: react-native local image not showing ios 
Javascript :: format moment to (dd-mm-yyy hh:mm:ss 
Javascript :: javascript verbatim string 
Javascript :: eslint resolve error unable to lead resolver 
Javascript :: xslt "node to string" 
Javascript :: html css and javascript for web developers 
Javascript :: detect finishing write react input 
Javascript :: vue router accept params null 
Javascript :: what regular express will match valid internation number 
Javascript :: javascript cast everything to string 
Javascript :: angular ng build setting body min-width 
Javascript :: Detect backspace pressed eventlistener 
Javascript :: javascript random to abs 
Javascript :: use variable in form action vuejs 
Javascript :: jquery image onerror not working 
Javascript :: destructring global state at one place 
Javascript :: cookie clicker get all badges hack 
Javascript :: poo javascript heritage 
Javascript :: return array odd or even outlier 
Javascript :: Das komplette JavaScript in den Footer laden 
Javascript :: typeof regex 
Javascript :: how to use classnames 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =