【发布时间】:2016-08-06 13:24:15
【问题描述】:
我正在尝试通过 AJAX 将表单变量发送到 PHP,并在 console.log 中显示结果。但是控制台始终没有显示数据的价值。我不知道怎么了。到目前为止我所拥有的:
部分 jQuery 代码:
...
init: function() {
this.on('success', function(csvFile, json) {
// AJAX
$.ajax({
url : "tests.php",
type : "POST",
data : this.csvFile
}).done(function (data) {
// Bei Erfolg
console.log("Erfolgreich:" + data);
}).fail(function() {
// Bei Fehler
console.log("Fehler!");
}).always(function() {
// Immer
console.log("Beendet!");
});
});
部分 HTML 代码:
<form action="tests.php" class="dropzone" id="myAwesomeDropzone">
<input type="text" name="testname" value="das bin ich"/>
</form>
PHP 代码:
if(!empty($_FILES)){
$test = $_FILES['file']['tmp_name'];
echo test;
}
if(!empty($_POST)){
$test2 = $_POST['testname'];
echo $test2;
}
【问题讨论】:
-
this.csvFile上您要传递的内容是什么? -
请在php文件的顶部加上
print_r($_POST);,这样我们就确定有输出,并检查是否收到POST数据。