2020-02-22 07:12
采纳率: 0%
浏览 75


I'm currently using 3 ajax call methods (3 of them are executing back-to-back). I must have a time delay in between the second ajax call and the third one. If I add "async:false" in the second ajax, everything works like a charm. However, I found out that this is really a terrible practice and shouldn't be using. So I decided to try an async/await. This is my first time, so have no luck. I would be really grateful if you guys could add some explanations so I can learn. Thank you so much.

//This is the second ajax method that I've been trying to use async/await
async function InsertAssignments(data) {
    var insertNewData = api + "/Point/insert_data/";
    await $.ajax({
        type: "POST",
        url: insertNewData + data,
        dataType: "json",
        data: data,
        timeout: 30000,
        success: function (data) {
        error: function (xhr, status, error) {
            $('#gridMessage').html(xhr.responseText).css("color", "red");

and then I'm calling InsertAssignments(data) somewhere.

图片转代码服务由CSDN问答提供 功能建议


我当前正在使用3个ajax调用方法(其中3个正在背对背执行)。 我必须在第二个ajax调用和第三个ajax调用之间有时间延迟。 如果我在第二个ajax中添加“ async:false”,则所有内容都像一个超级按钮。 但是,我发现这确实是一种可怕的做法,不应该使用。 所以我决定尝试异步/等待。 这是我第一次,所以没有运气。 如果你们能添加一些解释以便我学习,我将非常感谢。 非常感谢。 </ p>

  //这是我一直尝试使用async / await的第二个ajax方法
     var insertNewData = api +“ / Point / insert_data /”;
     等待$ .ajax({
         输入:“ POST”,
         网址:insertNewData +数据,
         dataType:“ json”,
             $(“#mainGrid”)。data(“ kendoGrid”)。dataSource.read();
             $(“#ListBox1”)。data(“ kendoListBox”)。dataSource.read();
             $(“#ListBox2”)。data(“ kendoListBox”)。dataSource.read();
             $('#gridMessage')。html(xhr.responseText).css(“ color”,“ red”);
 </ code> </ pre>


然后我在某个地方调用InsertAssignments(data)。</ p>      </ div>

1条回答 默认 最新

相关推荐 更多相似问题