简体   繁体   English

我想显示数据库结果而不重新加载页面

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

相关问题 我想在不重新加载页面的情况下从数据库显示div中的数据。 我该怎么做? - I want to show my data in div from database without reloading the page. How I can do this? 你好,我需要不断地从数据库中显示一个值而不重新加载页面 - Hello, i need to show a value from database constantly without reloading page 从数据库删除数据而无需重新加载页面 - Delete data from database without reloading the page 我想更改页面内容而不重新加载角度6 - I want to change the page content without reloading in angular 6 我想获得结果而无需再次重新加载页面。 (异步) - I want to get results without reloading the page again. (Asynchronously) 更新数据库而无需重新加载页面 - Update database without reloading page 如何在不重新加载页面或刷新地图的情况下(从SQL数据库)更新标记的位置? - How can I update the position of my marker (from SQL database) without reloading the page, or refreshing the map? 如何在不重新加载页面的情况下用数据库更新游戏的高分? - How can I update the highscore of a game with a database without reloading the page? 从数据库填充下拉列表框而无需重新加载页面 - Populating a dropdown box from a database without reloading the page Laravel Fullcalendar从数据库刷新事件,而无需重新加载页面 - Laravel Fullcalendar refresh events from database without reloading the page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM