首先,我是 javascript 的新手,我从 3 周开始就面临这个问题,并尝试调试它,但没有找到任何解决方案,所以问题是当我在我的 Blade 文件中编写一段新的 js 代码时,它可以正常工作 5-10几分钟后没有响应,控制台甚至没有显示任何 js 错误
我还使用了以下命令php artisan cache:clear
php artisan view:clear
没有任何反应然后我创建了新的 laravel 项目,它的版本是 5.8 并尝试在它但它在其中工作正常但在我的旧项目中没有工作然后我升级它的版本相同的问题然后我将我的所有文件从旧项目转移到新创建的项目然后 javascript 工作正常并且在一段时间后同样的问题开始然后我意识到添加新的当我删除新的代码行时,我的代码中的一段代码使代码无法工作它工作正常我不知道为什么当我添加 var info = {!! json_encode($pdata->toArray()) !!};
它可以正常工作一段时间然后整个 js 代码停止工作然后我删除这行代码再次开始工作
<script>
var button=document.getElementById('claps');
var not_span=document.getElementById('notifications');
var not_butn=document.getElementById("notification-btn" );
var message=document.getElementById('message');
var trash =document.getElementById('trash');
var info = {!! json_encode($pdata->toArray()) !!};
var jsoninf=JSON.stringfy(info);
count1=0;
count2=0;
button.onclick=function()
{
count1=count1+1;
button.innerHTML=count1;
// not_span.innerHTML="*"+count1;
message.innerHTML=jsoninf + " Claped on your post";
}
button.onmouseover=function()
{
button.innerHTML=count1;
}
button.onmouseout=function()
{
button.innerHTML='<img src="https://img.icons8.com/color/30/000000/applause.png">'+'Claps';
}
not_butn.onclick=function()
{
not_span.style.display='none';
}
trash.onclick=function()
{
count2=count2+1;
trash.innerHTML=count2;
//not_span.innerHTML=count2;
message.innerHTML="Abubakar" + "Trashed you post";
}
trash.onmouseover=function ()
{
trash.innerHTML=count2;
}
trash.onmouseout=function ()
{
trash.innerHTML='<img src="https://img.icons8.com/color/30/000000/delete.png">'+" Trash";
}
</script>
我的chrome控制台没有js代码相关的错误
最佳答案
此代码将在 blade 中执行
var info = @json($pdata->toArray());
// var jsoninf=JSON.stringfy(info); // remove this
info 变量将成为 javascript 对象/数组。您不需要解析它, Blade 将以这种方式为您完成工作。
关于javascript - 在 laravel blade 文件中,javascript 在我添加新代码行一段时间后停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57341085/