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

211
Views
NULL Post Data in Service Worker using Fetch API

I have this code in my service worker file that saves the PushMessage subscription:

var hostURI = window.location.protocol + "//" + window.location.host;

async function saveSubscription(subscription) {
    await fetch(hostURI + 'app/saveToken', {
            method: 'POST',
            mode: 'cors',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
            cache: 'default',
            body: JSON.stringify(subscription) //PushMessage object
        })
        .then(response => response.json())
        .then(data => console.log(data)); //check response
}

This works fine on my local but on the production server, the backend (PHP) says that the POST data is NULL. This is my test code on the server side:

public function saveToken() {
   $postData = (array) $this->request->getPost(); // get all post data
   $data['post'] = $postData;
   return $this->response->setJSON($data); // return as json
}

For further information, I don't know if this is related but my application is on the sublink so my base url is www.website.com/app.

I'm using CodeIgniter4 and IIS on server side.

about 4 years ago · Juan Pablo Isaza
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!