【发布时间】:2019-10-16 10:44:41
【问题描述】:
我正在使用$.post() 将数据推送到php 文件。但是当我创建var_dump 时,$_POST 是空的。
JS script:
$('#Notes').on("click", function (e) {
e.preventDefault();
let $id = $(document).getUrlParam("varname");
let $text = $(this).attr('data');
let $notes = prompt("Modifier la note", $text);
console.log($text, $id, $notes);
if ($notes !== null || $notes !== "") {
$.post(
'../buckets/update_note.buckets.php',
{
id: $id,
notes: $notes,
},
function (data) {
console.log('Data Id : ',data.id);
console.log('Data Name : ',data.name);
})
.then(r =>{
location.replace('../buckets/update_note.buckets.php');
})
}
在 php 文件中:
<?php
var_dump($_POST);
var_dump($_GET);
js 中的第一个 console.log 向我显示 3 个变量的值,但回调中的 console.log 向我显示 undefined。但我在网络调试器中看到:
Form Data
id: xxxx
notes: xxxx
有什么想法吗?
【问题讨论】:
标签: javascript php jquery post