代码之家  ›  专栏  ›  技术社区  ›  Mauro Sampietro

从JS获取POST并从PHP读取响应

  •  -1
  • Mauro Sampietro  · 技术社区  · 5 年前

    我正在收集表格中的数据 称之为js:

    fetch('process.php', {
        method: 'POST',
        body: formData,
    }).then(response => alert( response ) );
    

     echo json_encode('Upload completato correttamente');
    

    但我无法在警报中显示信息: 我只得到“[对象承诺]”,并在玩着回应,我似乎看不懂这条消息。

    有什么帮助吗?

    1 回复  |  直到 5 年前
        1
  •  1
  •   Juliar Nasution    5 年前

    你需要像这样分析你的结果

    fetch('process.php', {
        method: 'POST',
        body: formData,
    }).then(response => response.json() ).then(result=>{
     alert(result);
    });
    

        2
  •  1
  •   Mauro Sampietro    5 年前

    我可以通过控制台发现php代码中有一个问题。 它阻止了以下正确代码的正常工作:

    fetch('process.php', { method: 'POST', body: formData })
      .then(response => response.text() )
      .then(result=>{ alert(result); });
    

    推荐文章