Jquery 更新视图上的数据而不重新测量页面-Laravel

Jquery 更新视图上的数据而不重新测量页面-Laravel,jquery,ajax,laravel,autoload,Jquery,Ajax,Laravel,Autoload,我想在60秒后频繁加载数据,而不刷新页面。代码行是 <div id="callmeauto">@include('custome.myquestionodds')</div> 使用setInterval60秒 函数loaddata(){ $.ajax({ url:“{url('custome/myQuestionLobbits')}}”, 键入:“GET”, 成功:功能(数据){ $('#callmeauto').html(数据); } }); } $(文档)

我想在60秒后频繁加载数据,而不刷新页面。代码行是

<div id="callmeauto">@include('custome.myquestionodds')</div>

使用
setInterval
60秒

函数loaddata(){
$.ajax({
url:“{url('custome/myQuestionLobbits')}}”,
键入:“GET”,
成功:功能(数据){
$('#callmeauto').html(数据);
}     
});
}
$(文档).ready(函数(){
设置间隔(载荷数据,60000);
});

使用前端框架从端点获取JSON格式数据的更好方法

例如,您可以尝试使用框架。 很简单,你的问题就会这样解决

Vue({
    el: '#callmeauto',
    data: {
        contentToRender: "",
    },
    created() {
        this.loadContent();
        setInterval(this.loadContent, 60000)
    },
    methods: {
        loadContent(){
            axios.get('/custome/myquestionodds').then((response)=>{
                this.contentToRender = response.data;
            })
        }
    }
});
在模板中,您只需使用模板语法:

<div id="callmeauto">{{ contentToRender }}</div>
{{contentorender}
要使用vue.js,您需要安装它。还有用于进行ajax调用的库。 通过CDN简化了流程:

<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js></script>

错误:


它没有替换我要加载的视图的“callmeauto”div.Route中的旧数据或内部HTML内容Route::get('/custome/myQuestionLobbs',function(){return view::make('custome.myQuestionLobbs');});所以你需要每60秒调用ajax来获取更新的数据。我试过这个。我可以从检查中提取的错误:加载资源失败:服务器响应状态为500()app.js:4 GET www.example.com/custome/MyQuestionLobbits 500 send@app.js:4检查inspect元素+网络+错误中的错误,查看您收到的错误。“contentToRender”是undefined@MdNurulAfsarPervez我不知道你的结局如何。尝试console.log(响应);
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js></script>
app.js:4 GET https://example.com/custome/myquestionodds 500
send           @    app.js:4
ajax           @    app.js:4
loaddata       @    (index):1366
setInterval (async)     
(anonymous)    @    (index):1376
j              @    app.js:2
k              @    app.js:2
setTimeout (async)      
(anonymous)    @    app.js:2
i              @    app.js:2
fireWith       @    app.js:2
fire           @    app.js:2
i              @    app.js:2
fireWith       @    app.js:2
ready          @    app.js:2
S              @    app.js:3