Is it possible to utilize a JSON file to input events into FullCalendar that can accommodate multiple users?

Here's how I'm integrating event information from my database with FullCalendar using PHP:

  1. Retrieve event information from the database.
  2. Organize the data into an array and customize formatting, colors, etc.
  3. Convert the array to JSON format using json_encode.
  4. Save the file on my server as "results.json".

In my JavaScript code, I then use this file to populate my Calendar object:

$('#calendar').fullCalendar({
    events: 'results.json'
});

Everything seems to be working smoothly so far.

However, here is a concerning scenario:

What if multiple users are utilizing the system?

For instance, Jim queries the database for his events and saves them to results.json.

At the same time, Sue visits the page, retrieves her events, and writes them to the same results.json file.

This could potentially lead to unexpected events showing up on their respective calendars!

I have come across suggestions about using socket.io or transitioning to WebSockets for real-time applications. While these technologies seem helpful for interactive chat sessions, in my case, each user interacts with their own data rather than engaging in live updates. Does this mean that every user should maintain their own JSON file? That approach seems cumbersome. Alternatively, should the file be stored locally on their devices? However, this raises concerns regarding permissions and security.

Do you have any recommendations or advice to share on this matter?

Answer №1

Special thanks to Roljhon and Archer for pointing out my mistake in framing the question.

To address the inquiry above directly: DO NOT save a file to the server with data that will continuously change for each user. There is a more efficient approach.

The TRUE question is, once I have data stored in a PHP variable, how can I transfer it to JavaScript?

You can find a comprehensive explanation here: How to pass variables and data from PHP to JavaScript?

This resource details how to utilize AJAX, manipulate the DOM in JavaScript, or even directly input your PHP variable into a JavaScript variable. (I was unaware this was possible.)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Socket io Simplified: Embracing the Power of Drag

I'm currently in the process of developing a multiplayer card game using node, express, and socket io. However, I am facing some difficulties when it comes to transmitting drag and drop actions performed by one player to another connected player' ...

Tips for preventing duplicate triggering of a broadcast event from app.js in AngularJS

Within the app.js file, I am utilizing a callback function that broadcasts on the $rootScope to trigger a method in the second controller. function onSuccess(state) { if (state != true) { } else { $rootScope.$broadcast(&a ...

When using testthat, the 'expect_equal' function may sometimes unexpectedly return an error, even when the actual output matches the expected output perfectly

I am currently in the process of developing a test script to verify modifications made based on my logic. The expected and actual outputs are JSON files that should be identical. My main goal is to compare the actual output with the expected output. Initia ...

Step-by-step guide to implementing a sticky header while scrolling

How can I implement a fixed header on scroll, like the one seen on this website: www.avauntmagazine.com Here is the HTML for my header: <div class="bloc bgc-wild-blue-yonder l-bloc " id="bloc-1"> <div class="container bloc-sm"> &l ...

"Caution: The `className` property did not align" when configuring a theme provider within Next.js

I'm currently working on developing a theme provider using the Context API to manage the application's theme, which is applied as a className on the body element. The implementation of the context is quite straightforward. When initializing the ...

In Express.js, the value of req.body.data is not defined

Recently, I've been delving into nodejs and express js. My aim is to send a json object to my nodejs application using postman. Below is the code snippet from my app: var express = require("express"); var bodyParser = require('body-parser') ...

Saving the selections from two drop-down menus into a single variable

I have a requirement to store the user selected values from two dropdown menus. These dropdowns are created using the selectize library in HTML: <div style="max-width: 200px"> <select id="dropdown-1" ...

Expressing the power of multiple nested routers

Can multiple nested routers be implemented in an Express server? Imagine running a vehicle servicing business and wanting to organize the API into different services, each with its own set of actions: app.use('/clean', cleanRoutes); app.use(&apo ...

Creating a dynamic object for a React component by utilizing props

I currently have a component that displays a grid of 6 items. These items are hard-coded as gridItems. My goal is to make this component dynamic by allowing it to render specific items based on props passed to it. Instead of always displaying 6 items, I ...

Exploring the functionalities of AngularJS' ng-options when working with select elements

In my search through other posts, I came across this issue but couldn't find a solution. Here is the array in question: $scope.items = [ {ID: '000001', Title: 'Chicago'}, {ID: '000002', Title: 'New York' ...

JavaScript sorted arrays are an efficient way to keep data

In my dataset, I have an array of objects representing various products. Each product object includes a field called ratingReviews and another field called price, which can either be a string or an object. If the price is represented as an object, it conta ...

Ways to make a button blink using AngularJS

Currently working on an AngularJS SPA application where a button is present in the front-end HTML page. When this button is clicked, it triggers an operation which takes some time to complete. I want to inform the user that the operation is still in prog ...

Apollo Client is not properly sending non-server-side rendered requests in conjunction with Next.js

I'm facing a challenge where only server-side requests are being transmitted by the Apollo Client. As far as I know, there should be a client created during initialization in the _app file for non-SSR requests, and another when an SSR request is requi ...

I need help with a process to extract information from a database and convert it into an object specifically for my situation

Currently, I am utilizing the postgres row_to_json function to retrieve data that has been stored using JSON.stringify(). However, upon retrieval and attempting to parse it with JSON.parse(), an error message stating "unexpected token ," is returned. The ...

Can a collapse that was saved in a separate file be displayed on the requested page?

Imagine having a navigation bar on your website's index page with four buttons, each leading to a different page. What if you wanted to bring all those separate pages together into one by using collapsible elements? That's the challenge this user ...

Adjust the child content within a React component based on the element's width, rather than the overall window size, by implementing dynamic resizing without fixed breakpoints

I am working with a react component that displays a div containing menu items which are aligned horizontally using inline-block. The menu items have text labels "Toy Store", "Configure your Toy", and "About Us". My challenge is to dynamically change the ...

Tips for sending a POST request with JSON data through the Google API client library in Java

Struggling to make a successful post request using the google api client library. This is the current snippet being utilized UrlEncodedContent urlEncodedContent = new UrlEncodedContent(paramMap); //paramMap consists of email and password keypairs HttpR ...

Explaining the process of defining `this.props` and storing data in the global Redux state

I am currently diving into the world of react and Redux and I'm using a react project on GitHub called overcode/rovercode-ui as a learning tool for understanding react and Redux. As I explore this project, I have come across some intriguing questions. ...

Execute JavaScript function after completion of CSS animation using jQuery

I'm working on an accordion feature that uses CSS animation to expand the clicked item. The expansion is triggered by li:target. However, I'm facing an issue where when clicking on an item, the scroll position doesn't align correctly with t ...

The event handler onClick is unresponsive in the button element within a React component

Hey there, I'm new to React and I'm having an issue with a class-based component. Below is my component that I'm calling inside another React component. I just want the temp function to be called when onClick is triggered, but it's not ...