Ich rufe eine Ajax
Funktion von einer anderen Funktion und möchte die Antwort erhalten und dann die Json
analysieren, um sie zu neuen div
s zuweisen.Verwenden von/Schleifen Antwort von Ajax Anruf von einer anderen Funktion
Der Anruf wird wie folgt vorgenommen: thedata = GetChequesByBatchID(batchId);
und dies ist die Antwort:
Dann habe ich eine Schleife durch die Antwort bin versucht, aber das ist, wo das Problem ist. Ich bin nicht sicher, wie man die Antwort erhält und durch die thedata
Schleife. Diese Daten sollten der htmlFromJson
zugewiesen werden, so dass sie als Gruppe divs
in die TR
eingefügt wird. Irgendwelche Ideen?
Meine Funktion:
<script type="text/javascript">
$(document).ready(function (params) {
var batchId;
var thedata;
var htmlFromJson = "";
$('.showDetails').click(function() {
// Show Details DIV
$(this).closest('tr').find('.details').toggle('fast');
batchId = $(this).data('batchid');
thedata = GetChequesByBatchID(batchId);
var json = jQuery.parseJSON(thedata);
$.each(json, function() {
htmlFromJson = htmlFromJson + ('<div class="ListTaskName">' + this.ChequeID + '</div>' +
'<div class="ListTaskDescription">' + this.ChequeNumber + '</div>' +
'<div class="ListTaskDescription">' + this.ChequeAccountNumber + '</div>' +
'<div class="ListTaskDescription">' + this.ChequeAmount + '</div>');
});
}).toggle(
function() {
// Trigger text/html to toggle to when hiding.
$(this).html('Hide Details').stop();
$(this).closest("tr").after("<tr class='456456'><td></td><td colspan = '999'>" + '<div class="zzss">' + htmlFromJson + '</div></td></tr>');
},
function() {
// Trigger text/html to toggle to when showing.
$(this).html('Show Details').stop();
//$(this).find('.zoom').remove();
$('tr.456456').remove();
}
);
});
</script>
Meine Ajax-Funktion:
<script type="text/javascript">
function GetChequesByBatchID(BatchID) {
var xss;
var qstring = '?' + jQuery.param({ 'BatchID': BatchID });
return $.ajax({
url: '<%=ResolveUrl("~/DesktopModules/PsaMain/API/ModuleTask/GetChequesByBatchID")%>' + qstring,
type: "GET",
cache: false,
contentType: "application/json; charset=utf-8",
success: function (result) {
jQuery.parseJSON(result); //the response
},
error: function (response) {
alert("1 " + response.responseText);
},
failure: function (response) {
alert("2 " + response.responseText);
}
});
return xss;
}
</script>