[英]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.