Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript fetch request GET

// Update fields in form based on API GET request
function update_form_fields(term, field){ 
  fetch("/api/profiles/?format=json")
    .then((response)=>{
    return response.json();
  }).then((data) => {
    let profile = data.find(el => el[field] == term);      
    document.getElementById("name-input").value = profile.name;
    document.getElementById("email-input").value = profile.email;
  });}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #fetch #request #GET
ADD COMMENT
Topic
Name
9+5 =