doulang7699 2018-04-16 09:17
浏览 47
已采纳

Laravel jQuery - 如果数据库中存在某些行,则每分钟检查一次

Currently I'm working on a project which requires a little jQuery to get something done. The thing I need to get done is to check every minute if a certain row with a certain ID in the database exists.

I have a blade file where the user gets to when he or she finished a certain step. Within this blade file, There needs to be a jQuery script that checks every minute if a row with a certain webshop->id exists in the database table called "Droplets". If It does, A progress bar needs to be set a certain width. How can I achieve that?

My attempt so far looks like this:

HTML (Progress-install)

<div class="col-md-12 mb-3">
 <div class="progress mb-3">
   <div id="progress-install" class="progress-bar andcode-progress progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100" style="width: 10%"></div>
 </div>
</div>

The jQuery script needs to check if there is a row in the table called "Droplet" with the webshop->id which I can call by doing {{ webshop->id }} in my blade file

jQuery attempt

$(document).ready(function() {

    var checkdb = function () {
        $.ajax({
           type: 'POST',
           url: '/droplet/get/' {{ $webshop->id }},
           data: '_token = <?php echo csrf_token() ?>',
           success:function(data) {
               $("#dropletInfo").html(data.info)
           }
        });

        var ele = document.getElementById('progress-install');
        ele.style.width = 30+'%';

    };
    setInterval(checkdb(),1000 * 60);
})

The route that the jQuery script calls is

Route::post('/droplet/get/{id}', 'DropletController@getAll')->name('getAllDroplets');

and looks like this:

public function getAll($id)
{
    $info = Droplet::where("webshop_id", "=", $id)->get();

    return response()->json(array($info));
}

How can I achieve the above?

  • 写回答

1条回答 默认 最新

  • dpdjv9559 2018-04-16 09:39
    关注

    Here your url is not build correctly:

    url: '/droplet/get/' {{ $webshop->id }},  // here you are missing the contenation, so change it to:
    
    url: '/droplet/get/' + {{ $webshop->id }},
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)