Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

212
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda