目前我陷入了这个问题,
我目前正在将 json 发布到一个可以工作的 php 页面,但是我也想将一个变量发布到这个 php 页面,但不知道如何包含它。
这是当前代码
$.ajax({
method: "POST",
url: "sjfb-save.php",
data: data,
dataType: 'json',
success: function (msg) {
console.log(msg);
$('.alert').removeClass('hide');
$("html, body").animate({ scrollTop: 0 }, "fast");
//Demo only
$('.alert textarea').val(JSON.stringify(fields));
}
并说变量是$example; 该变量只是一个字符串。
这是检索 json 的代码
$form_data = json_decode(file_get_contents('php://input'));
最佳答案
您可以将带有此类变量的 GET
查询附加到请求的 URL:
var v = '...';
$.ajax({
method: "POST",
url: "sjfb-save.php?var="+encodeURI(v),
...
});
然后发送的变量将通过 $_GET
全局数组可用。
$_GET['var']
关于javascript - 如何将多种数据/数据类型发布到 php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36318804/