In meiner asp.net Mvc app machen, habe ich Schaltfläche klicken, die zu einem Javascript Punkte, dieWie Javascript ausführen Funktion synchron
function OnButtonClick(s, e, startUrl, progressUrl) {
Fetch(progressUrl);
ImportUpdate(startUrl);
}
Aktion ajax jquery an einen Controller Fetch und ImportUpdate sind aufruft.
function Fetch(progressUrl) {
positionDate = ReportingPositionDate.GetDate().toDateString();
$.ajax({
type: 'POST',
url: "@Url.Action("BloombergFet", "ImportData")",
data: JSON.stringify({ positionDate: positionDate }),
dataType: "text",
contentType: "application/json; charset=utf-8",
beforeSend: function() { lpBloomberg.Show(); },
success: function (msg) {
ImportSuccessMessage.SetText(msg);
lpBloomberg.Hide();
lpImport.Show();
},
error: function (xhr, textStatus, errorThrown) {
lpBloomberg.Hide()
}
});
}
function ImportUpdate(progressUrl) {
positionDate = ReportingPositionDate.GetDate().toDateString();
myProgressBar.Show;
$.ajax({
type: 'POST',
url: "@Url.Action("ProcessImportRecord", "ImportData")",
data: JSON.stringify({ positionDate: positionDate }),
dataType: "text",
contentType: "application/json; charset=utf-8",
beforeSend: function() { lpImport.Show(); },
success: function (msg) {
ImportDataGridView.PerformCallback();
ImportSuccessMessage.SetVisible(true);
ImportSuccessMessage.SetText(msg);
lpImport.Hide();
},
error: function (xhr, textStatus, errorThrown) {
ImportErrorMessage.SetVisible(true);
ImportErrorMessage.SetText(xhr.statusText)
}
});
}
Derzeit beide Methoden Fetch(progressUrl)
und ImportUpdate(progressUrl)
sind zugleich genannt. Ich möchte Fetch(progressUrl)
abschließen und anschließend ImportUpdate ausführen.
Wie erreiche ich das? Schätze alle Hilfe.
Rückrufe. Rückrufe verwenden –
Wenn Sie immer Fetch gefolgt von ImportUpdate abrufen möchten, würde ich vorschlagen, dass Sie sie zu einem einzigen API-Aufruf kombinieren. – James
danke James. Das hat funktioniert – ProgSky