Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

javascript - PHP undefined array index from fetch api, but works fine through ajax?

AJAX

 $.ajax({
            type: 'POST',
            data: {"doc-id":doc},
            url: '../src/update_docs.php',
            dataType:"json",

In php

$_POST['doc-id'] //224

Fetch API

fetch('/src/project.php/',{
  method: 'POST',
  headers: {
     'Content-Type': 'application/json',
   },
      credentials: 'same-origin',
      body:{"doc-id":doc},
})

In php

$_POST['doc-id'] //Undefined array index

I have tried many different combinations, such as JSON.stringify, which still results in the same. Is there a way I can send the data with the same method in the curly brackets but allow php to get the index?

question from:https://stackoverflow.com/questions/65641388/php-undefined-array-index-from-fetch-api-but-works-fine-through-ajax

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...