[英]I want to show result from database without reloading the page
I am working with laravel
. 我正在与
laravel
一起工作。 I have two div
. 我有两个
div
。 One div
is to show some output from database and other div
is for showing some output from database. 一个
div
用于显示数据库的某些输出,而另一个div
用于显示数据库的某些输出。
Let me show my code. 让我展示我的代码。
<div id="pending">
@foreach($pendings as $pending)
{{ $pending->title }}
<br>
@endforeach
<div id="accepted">
@foreach($accepteds as $accepted)
{{ $accepted->title }}
<br>
@endforeach
When an user will enter to the page, I want to show him pending div
or pending data. 当用户进入页面时,我想向他显示待处理的
div
或待处理的数据。 Then I want to keep two button. 然后我要保持两个按钮。 One is PENDING and other one is ACCEPTED.
一种是待定,另一种是接受。 And I want to show pending
div
or pending data when user will click pending button as well as accepted div
or accepted data when user will click accepted button. 我想在用户单击待处理按钮时显示待处理的
div
或待处理数据,以及当用户单击接受按钮时显示已接受的div
或已接受数据。 Anyone please help me. 有人请帮助我。
One more think I don't have much knowledge about AJAX or JQuery. 还有人认为我对AJAX或JQuery没有太多的了解。
create two buttons with ids button_1 & button_2 and bind db result in single div.You can try below codes 创建两个ID为button_1和button_2的按钮,并将db结果绑定到单个div中。您可以尝试以下代码
function sendAjaxRequest(element,urlToSend) {
var clickedButton = element;
$.ajax({type: "POST",
url: urlToSend,
data: { id: clickedButton.val(), access_token: $("#access_token").val() },
success:function(result){
/*can add logic for html or json data*/
$("#divid").append(result);
},
error:function(result)
{
alert('error');
}
});
}
$(document).ready(function(){
$("#button_1").click(function(e){
e.preventDefault();
sendAjaxRequest($(this),'/pages/test/');
});
$("#button_2").click(function(e){
e.preventDefault();
sendAjaxRequest($(this),'/pages/test/');
});
});
我已经通过Bootstrap Tabs和Pills做到了这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.