【发布时间】:2020-08-02 08:45:08
【问题描述】:
我有这个tab.php 页面,它基本上是网站的索引。它包含所有 JavaScript 和 HTML 代码。
我正在尝试从这个页面发送一些数组到 PHP 页面,而不是执行更新查询,将数组上传到我的 phpmyadmin。
我在tab.php 中使用了这段代码,但它不起作用。
var send_array = {
"red": redtruppe,
"blue": bluetruppe,
"orange": orangetruppe,
"purple": purpletruppe,
"black": blacktruppe,
"green": greentruppe
};
$.ajax({
type: "POST",
url: "send.php",
data: { TruppeJson : send_array },
success: function() {
alert("Success");
}
});
send.php 页面现在是这样的:
<?php
$myTruppe = json_decode($_POST['TruppeJson']);
echo '<script>console.log('.$myTruppe.')</script>';
?>
成功警报似乎有效,但send.php 显然无效,有什么建议吗?
【问题讨论】:
-
send.php以什么方式失败?<script>console.log.....etc将是 POST 请求返回的数据...如果您有success: function(result) { alert(result); },您会看到警告文本,即它会警告<script>console.log('... the json will be here ...')</script>- 可能不是您所期望的,但这就是您所写的跨度> -
首先感谢您的回答,我尝试使用 "success: function(result) { alert(result); }" 并更改 echo 但是,我的 json 文件似乎是空的
-
没有json文件
-
对不起,我的意思是数组
标签: javascript php arrays json ajax