Ich versuche, eine Reihe über Ajax zu senden, so habe ich den folgenden Code:Ajax keine Daten sendet als Parameter
Hier ist der Code
function fncGetChecksToProcess() {
var allChecks = [];
$('input[type=text]').each(function() {
var key = $(this).attr("id").replace("txt_", "");
allChecks[key] = [];
});
$('input[type=checkbox]').each(function() {
if (this.checked) {
var className = $(this).attr('class');
if (className.includes('box_total_')) {
var ref = $(this).attr('id').replace("box_total_", "");
var amountDetails = [];
var docNs = [];
$('.' + ref).each(function() {
amountDetails.push(parseFloat($(this).closest('td').next().html().replace("$", "").replace(",", "")));
docNs.push($(this).attr('id').replace("box_", ""));
});
allChecks[ref].push({
docN: docNs,
amountTot: $("#sub_" + ref).text(),
amountDetails: amountDetails,
chkNum: $("#txt_" + ref).val()
});
} else {
var docN = $(this).attr('id').replace("box_", "");
allChecks[className].push({
docN: docN,
amountTot: $("#td_" + docN).text(),
amountDetails: "",
chkNum: $("#txt_" + className).val()
});
}
}
});
return allChecks;
}
$(document).ready(function() {
$("#btn").click(function() {
var checks = fncGetChecksToProcess();
console.log(checks);
$.ajax({
cache: false,
type: 'POST',
data: {
allChecks: checks
},
url: '/process',
beforeSend: function() {
console.log("Processing your checks please wait...");
},
success: function(response) {
console.log(response);
},
error: function() {
console.log("Error");
}
});
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="app.js"></script>
</head>
<body>
<table id="table" class="tablesorter" width="100%" cellspacing="0">
<thead>
<tr>
<th>H1</th>
<th>H2</th>
<th>H3</th>
<th>H4</th>
<th>H5</th>
<th></th>
<th>H6</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>11002WR</td>
<td>201100</td>
<td>A</td>
<td class="center"><input class="11002WR" id="box_201100" type="checkbox" /></td>
<td id="td_201100">$320.00</td>
</tr>
<tr>
<td colspan="3"></td>
<td>Check. No</td>
<td><input id="txt_11002WR" type="text"></td>
<td><input id="box_total_11002WR" class="box_total_201100" type="checkbox" /></td>
<td id="sub_11002WR">$12.00</td>
</tbody>
</table>
<input id="btn" type="button" value="Test" />
</body>
</html>
Bitte überprüfen Sie die zwei Kontrollkästchen und die Eingabe und drücken Sie auf den Test.
Die Konsole gibt das generierte Array aus, aber Ajax sendet es nicht.
Warum sendet mein Ajax-Anruf keine Parameter? Ich sehe sie nicht in der Chromkonsole.
Danke.
FYI können Sie '$ (" input [type = Checkbox] : checked ")' so brauchst du nicht 'if (this.checked)' – Barmar
danke für den Hinweis. Irgendwelche Ideen, warum ich die Ajax-Ausgabe habe –
Nein, habe diesen Teil noch nicht herausgefunden. – Barmar