Bring BD data with javascript

Asked

Viewed 513 times

1

Hello ! I have a MENU and a submenu within each item of this menu.

Every time I click on a menu item, it opens a sub-menu (accordion effect).
There’s a way to make a select within the database and work with the result of these select, within the JS ?

$(document).ready(function() {
    $('#calendar').fullCalendar({});
});

    $('#addEvent').click(function() {  

      //BUSCAR OS DADOS DO BANCO AQUI, PARA USA-LOS ALI EMBAIXO.
      $('#calendar').fullCalendar(
        'renderEvent',
        {
          title: 'Novo evento', // <-- Inserir os dados aqui
          start: '2016-03-31',  // <-- Inserir os dados aqui também
        }
      );
    });  

Note: I did not find anything, but worth mentioning. I am using laravel, I didn’t find anything, but maybe he has something to help with that...
Note: It is not mandatory to be javascript, but I don’t see how to use php to insert data into this block.

  • You need a programming language, php for example, but if you want to do it only in javascript you can use Node.js as the guy just quoted it now.

  • But is there any way to use PHP to pull the data when I click on the menu ? Because I would need to add the data in the event I showed in the code.

1 answer

1


If you want to use only Java Script, I recommend using Node.js. It is a platform built on the Javascript engine, you can make a complete application with back end using only Java Script.

Reference:https://nodejs.org

  • And would it be possible to use php to insert the data into that block of code that I showed ? as ? I spoke in JS, because I thought it would not be possible to use php there.

  • Yes of course but you first need to create your PHP file that does the query in the database, a php method that returns the data you want. And then via javascript make an ajax request, which goes in php and brings the data to javascript.

  • How am I using Laravel, besides telling the php file of the query, can you specify a method inside it? (Controller). Or should I create a separate file, just for this ?

  • 1

    It is right to create the controllers separate from the database query, using the MVC standard that the Laravel offers. I think you should better understand the concept of service, use a Restful to make the javascript ajax request, for your php. Study MVC with Laravel, see this class: https://www.youtube.com/watch?v=UdZ956XwoFY

Browser other questions tagged

You are not signed in. Login or sign up in order to post.