简体   繁体   English

Laravel jQuery-每分钟检查数据库中是否存在某些行

[英]Laravel jQuery - Check every minute if certain row exists in database

Currently I'm working on a project which requires a little jQuery to get something done. 目前,我正在一个需要一些jQuery才能完成工作的项目中。 The thing I need to get done is to check every minute if a certain row with a certain ID in the database exists. 我需要做的事情是每分钟检查数据库中是否存在具有特定ID的特定行。

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". 在此刀片文件中,需要有一个jQuery脚本,该脚本每分钟检查一次数据库表中是否存在名为“ Droplets”的带有特定webshop->id的行。 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) HTML(进度安装)

<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脚本需要检查表中是否有名为“ Droplet”的行,其中包含webshop->id ,我可以通过在刀片文件中进行{{ webshop->id }}来调用

jQuery attempt jQuery尝试

$(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 jQuery脚本调用的路由是

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? 如何实现以上目标?

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 }},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel jQuery-检查数据库中是否存在行 - Laravel jQuery - Check if row exists in database jQuery:检查包含特定值的表行是否已经存在 - jQuery: Check to see if table row containing certain values exists already 使用jQuery Mobile每分钟检查一次设备互联网连接 - Check device internet connection every minute with jquery mobile jQuery:检查是否存在具有特定类名的 div - jQuery: Check if div with certain class name exists Laravel - 检查 javascript 内的数据库中是否存在数据 - Laravel - check if a data exists in database within javascript 如何在使用 jQuery Laravel 提交表单之前检查数据库中是否已存在记录 - How to check if a record already exists in a database before submitting the form using jQuery Laravel 使用jQuery检查数据库行是否存在 - Checking if database row exists using jQuery jQuery AJAX检查数据库中是否存在电子邮件不工作 - jQuery AJAX check if email exists in database not working 每1分钟启动一次计时器 - Start timer every 1 minute Jquery jQuery-要求添加setTimeout函数将每5秒运行一次,以检查是否已定义jQuery(最长不超过1分钟) - jQuery - Require to add setTimeout function will run every 5 seconds to check if jQuery is defined or not upto 1 minute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM