Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda