データのリストを javascript 配列から php 配列に転送しようとしていますが、ajax でうまくいかないようです。誰かがこれを行う方法のコードを見せてもらえますか? これまでのところ、私が持っているものは次のとおりです。これは単なる配列です。
ジャバスクリプトvar dates;
// the dates array is then filled up here
// it contains information in the form {'2012-01-01', '2012-03-12', ...}
$.ajax({
type: "REQUEST",
url: "NAMEOFPHPFILE.php",
data: { sendData1 : dates },
success: function() {
alert("Attempting to transfer array -> AJAX");
}
});
var submissions;
// the submissions array is then filled up here
// it contains information in the form {int, int, ...}
// ect ......... with 3 more arrays using { sendData2 : submissions },
PHP
<?php
$bDates = $_REQUEST['sendData1'];
// need to set this array = to the JavaScript dates array
$bSubmissions = $_REQUEST['sendData2'];
// need to set this array = to the JavaScript submissions array
?>
URL に情報がログインするのを防ぐために、REQUEST メソッドを使用したいと思います。 このコードは、REQUEST の代わりに POST を試行しても機能しません
.php ページの最後で、多数の配列を CSV ページに出力しています。ここで、配列を繰り返し処理し、それらの要素をファイルに配置します。これはすでに機能していますが、データを吐き出すことができるように、これらの配列の一部を JavaScript から PHP に転送する必要があります。それは次のようになります。
<?php
$stringData = "Dates, Number of Lines Changed, , Bug Dates, Arrivals, Fixed, Closed, Hold_";
for($i = 0; $i < sizeof($dataXAxis); $i++){
$date = substr($_REQUEST['Dates'][$i+1], 0, 24);
$stringData .= "$date, $dataYAxis[$i], , $bDates[$i], $bSubmissions[$i], $bCompletions[$i], $bDones[$i], $bRejections[$i]_";
}
echo '<BR><BR><a href="download_csv.php?csv=' . $stringData . '" target="_blank">Download Your CSV File</a>';
?>
AJAX が機能しないのはなぜですか? 配列は空に見えます...