2021年3月20日星期六

JavaScript function returning null |Get request using fetch

I'm new to javascript. I want to create a function which takes username and fetch data from my local api .It should return the object if the user exist or null otherwise. The problem is that it always returns null...Please tell me what is the issue .Thanks in advance here is my code

isUserExist=(username)=>{      fetch(`http://localhost:8000/customer/${username}`)      .then(response=>response.json())      .then(data=>{                 if(data!==null){              return data;           }       return null;  })  
https://stackoverflow.com/questions/66729039/javascript-function-returning-null-get-request-using-fetch March 21, 2021 at 01:06PM

没有评论:

发表评论