Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
React: onClick I want to download the csv files, with queryparam and if download fails due to wrong params want to display popup message

onClick I want to download the csv files, with queryparam and if download fails due to wrong params want to display popup message

Here is my onClick doSubmit method,

 const doSubmit = () => {
    let timeZoneoffset = new Date().getTimezoneOffset();
    let location = `${apiEndpoint}/export-device-data?fromDate=${fromDateTime}&toDate=${toDateTime}&userId=${values.userId}&deviceTypeId=${deviceId}&timeZoneoffset=${timeZoneoffset}`;
    window.open(location, '_blank');
  };

with the above code I am able to download the csv file if I pass the correct params values. But when I pass the incorrect params values getting error object in new tab:

{"status":false,"responseCode":400,"message":"Invalid Request"}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I would suggest you to make a "GET" AJAX call and only if you get 200 as the HTTP status code then you should open the popup and load the page. And if you get > 400 in HTTP status code then show a popup.

fetch("linkedin.com")
.then(data => {
if(data.status < 400)
//popup
else
//display error message
enter code here
})

But with this you ll end up sending 2 requests to load the page.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!