我在 JavaScript 中创建 JSON 数组时遇到问题。我的源代码如下所示:
数组1:
aOrderInformations[0] = BestellNummer;
aOrderInformations[1] = Lieferant;
aOrderInformations[2] = Bestellgrund;
aOrderInformations[3] = Besteller;
aOrderInformations[4] = Mitarbeiter;
aOrderInformations[5] = Standort;
aOrderInformations[6] = Gesellschaft;
aOrderInformations[7] = Bestelldatum;
aOrderInformations[8] = Begruendung;
aOrderInformations[9] = Lieferanschrift;
aOrderInformations[10] = Rechnungsanschrift;
aOrderInformations = new Array(aOrderInformations);
array2 来自带有 ajax 的服务器(这里是 PHP):
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM $sTable
WHERE BestellID = '".$bestellid."'
ORDER BY $sIndexColumn DESC
";
$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
while ($data = mysql_fetch_array($rResult))
{
$aPositions[] = $data;
}
echo json_encode( $aPositions );
array2(这里是 Javascript):
success: function(data) {
aPositions = data;
当我单独调试两个数组时,它将以正确的语法显示。但是当我尝试按如下方式将其发送到 php 时,它不会合并数组并仅显示一个数组:
{
"0": {
"0": "292",
"1": "1",
"2": "Microsoft",
"3": "Maus",
"4": "33355520",
"5": "MISCO Germany Inc.",
"6": "510014",
"7": "1",
"8": "22.02",
"9": "22.02",
"PostenID": "292",
"ProduktID": "1",
"Hersteller": "Microsoft",
"Beschreibung": "Maus",
"Produktnummer": "33355520",
"Lieferant": "MISCO Germany Inc.",
"Artikelnummer": "510014",
"Menge": "1",
"PreisNettoEinzeln": "22.02",
"PreisNettoGesamt": "22.02"
}
}
将组合数组发送到 php 的代码如下:
var postData = $.extend({}, aOrderInformations, aPositions);
var postData = JSON.stringify(postData);
if(!ajaxload2) {
alert(postData);
ajaxload2 = true;
$.ajax({
type : 'POST',
url : 'share/content/helper/writeorderdata.php',
cache: false,
dataType : 'json',
data: {postData:postData},
success: function() {
ajaxload2 = false;
}
});
}