drti52047 2018-03-30 11:51
浏览 72

AJAX多重回复

I'm diving into JavaScript and AJAX technologies now, and I understand AJAX and POST well with it. Now I wonder whether there's something like a broadcasting channel that my PHP code (in this case, Laravel controller) broadcast to, which then is received by JavaScript on the client side in order to manipulate something, say a process like this:

User clicks a button, a spinner is shown inside the button. Next to the button, there's a status label indicating the current process/task being processed. Finally, the button becomes a link or something else. So, what I want now is that I can update the status multiple times, since my current AJAX code will only receive one message, or one status, at the end of the process and that's it, nothing in between:

$.ajax({
   url: "/admin/test",
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    method: 'POST',
    dataType: 'json',
    data: {
        id: whatever
    },
    success: function(result)
    {
        console.log(result.status);
    }
});

Now I wonder how this further works.

  • 写回答

2条回答 默认 最新

  • dpp66953 2018-03-30 12:00
    关注

    You can make use of beforeSend event of ajax and use to start a progress bar and when it completes you can make progress bar width to 100%

    $.ajax({
        url: "/admin/test",
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        method: 'POST',
        dataType: 'json',
        data: {
            id: whatever
        },
        beforeSend : {
            // start progress bar
        },
        success: function(result)
        {
            console.log(result.status);
            // complete progress bar
        }
     });
    

    Additionally, you could use css to apply transition to give the feeling the of progress in progress bar.

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比