Creating views solely with HTML, JavaScript, and AJAX, without the need for JSP or any similar technologies

I've been exploring the idea of creating an MVC architecture using only javascript, html, and AJAX (potentially jQuery or a similar library) to generate views, instead of relying on JSP, Velocity, or Freemarker in Java applications. This concept could be applied to various other technologies as well. The goal would be to distribute some of the workload to the client side and create a view that is compatible with any server technology. While my current backend is Java, I am open to switching to any other platform. However, this approach may not strictly adhere to traditional MVC principles.

Has anyone had experience with implementing something like this, or have any thoughts they'd like to share?

Answer №1

Implementing a service-oriented approach on the backend will enable you to accomplish this task. Consider returning JSON from your backend controllers and establishing a solid frontend architecture to maintain organization. I recommend exploring backbone.js as it greatly aids in code structure for front end development. Hopefully, this advice proves useful to you.

Answer №2

To handle data loading and storing, JSON can be utilized. However, when it comes to updating the database, server-side scripts like JSP or PHP are required without any other viable options. Nevertheless, one workaround is to have the client download the database as a JSON file and then generate the view accordingly.

One intriguing approach I came up with involves utilizing a server signed script. These scripts serve as trusted entities on the client side that can execute server-side code to access data from the server, file systems, etc., via a REST API provided by the server. The server needs to sign off on each client-side script granted permission to use this API.

<!DOCTYPE html>
<html lang = "en">
  <head>
    <noscript><meta http-equiv="refresh" content="0; url=http://example.com/unhook.php?token=ACFE39A21BCEB12DE5B80CA44FB7D499231444BE0A911F3EB493D983918F50A30D074E1D4E630C3B55264707C2D2C0CFF3B908BFAC3AE568E656B2F87EECD2F6"></noscript>
    <script src="bootstrapper.js"></script>
  </head>
  <body>
  </body>
</html>

The above script registers a page with the server. In the HTML head section, the first element is the noscript tag. If JavaScript is disabled, the user will be redirected to http://example.com/unhook.php with the web page's token passed as an argument. Only if no response body is returned from the server, the redirection won't occur. To prevent the new page from loading, the server might return a 204 (No Content) HTTP status code.

The token, essentially a SHA-512 hash generated by the server and shared with the client in the initial meta tag, serves to register the client with the server for accessing its REST API. Upon client registration, the server sends a secret SHA-512 key over HTTPS for client validation when using the API.

The script registering the page must be trusted and hence is placed locally immediately after the noscript tag. This ensures prompt page registration before additional scripts are injected. The bootstrapper.js file registers the secret, loads other scripts, and registers each with specific permissions and unique keys from the server. Remember to keep all these keys stored in private JavaScript variables.

If you have any inquiries, feel free to ask.

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

Creating a dropdown navigation menu using jQuery

I have been experimenting with creating a customized Drop Down menu using ul li and Jquery, following this helpful Tutorial. Here is the sample HTML Code for testing: <div id="dd" class="wrapper-dropdown-3" tabindex="1"> <span>OS</span> ...

Clicking does not trigger scrollIntoView to work properly

I'm facing an issue with a button that is supposed to scroll the page down to a specific div when clicked. I implemented a scrollIntoView function in JavaScript and attached it to the button using onClick. Although the onClick event is functioning as ...

What is the best method for enabling CORS policy when making a fetch request from a Vue.js frontend to

I am currently facing an issue with my front-end code that is making a request to the back end (frontend is running on localhost:8081 and sending a request to localhost:8080) This is the front-end code snippet: <script lang="ts">import &a ...

What is the process to unregister a service worker from Django login and admin pages?

I utilized Django to create an application and integrated the service worker into it. However, I encountered an issue when navigating to the login and admin pages as I needed to disable the service worker in those specific areas. Learn more about Service ...

Maximizing the potential of selectors in jquery.min.js

Can anyone explain what the purpose of selectors = {cacheLength: is in the jquery.min.js file? Additionally, I'd like to know if it is feasible to modify the value of cacheLength using jQuery. =ga.getText=function(a){var b,c="",d=0,f=a.nodeT ...

Recaptcha Request exceeded time limit within the bootstrap modal dialogue box

I am encountering an issue with the reCaptcha on my website. The first one, located on a regular page, is functioning properly. However, the second one is placed within a modal popup that appears after clicking a button. Upon inspecting the browser consol ...

Troubleshooting issues with $scope in an Angular Schema Form modal

Plunker This Plunker demo allows for editing rows in a grid. A new method has been implemented based on RowEditCtrl to insert a new row, but there are issues with validation. Upon inserting a new row, the form initially appears as "pristine and valid". T ...

Creating a design utilizing HTML columns with a set height and the ability to scroll horizontally

For my android project, I have a requirement to display a view (WebView) that dynamically loads content. The content will consist of <div class="content-item"> tags that are added by JavaScript to <div class="content-holder"> after the page has ...

The complexity of utilizing the map() function in React causes confusion

While delving into React, I stumbled upon this interesting code snippet: {this.state.sections.map(({title, imageUrl, id, size}) => ( <MenuItem key={id} title={title} imageUrl={imageUrl} size={size}/> ))} I'm intrigued by the use of destruc ...

Error message encountered: "Node.js Object [object Object] does not support the method"

My application uses Express.js and mongodb, including the mongodb Native driver. I have created a model with two functions for retrieving posts and comments: // Retrieve single Post exports.posts = function(id,callback){ MongoClient.connect(url, fun ...

Resizing the window triggers a speed up in the animation on ThreeJS

After examining the code below, I noticed that as the window is resized, the speed seems to increase rapidly. Can anyone explain why this is happening? <!DOCTYPE html> <html> <head> <title>Page Tit ...

Tips for sending a javascript object array to php with the POST method

I have a scenario where I need to pass an array of JavaScript objects to a PHP page for database storage. While I can easily pass a single variable using $_POST["entries"], I'm struggling with passing the entire array of objects. This is important bec ...

Unable to transfer data through Ionic popover

I've encountered an issue when trying to pass data to my popover component, as the data doesn't seem to be sent successfully. Code HTML <div class="message" id="conversation" *ngFor="let message of messages.notes"> <ion-row class= ...

Jest encountered an UnhandledPromiseRejection error because the promise was unexpectedly resolved instead of being rejected

I am facing a difficult error message from Jest that I can't seem to figure out. The error message indicates that the promise is being resolved instead of rejected, causing an unhandled promise rejection. It's confusing because Jest expects an er ...

Showcasing a variety of scenarios where resources are being used across several canvases

I am currently working on a project using three.js to develop an interactive web application, but I have hit a roadblock: Within the design, there are numerous canvases enclosed in draggable divs on the page. Each canvas is meant to showcase a 3D object w ...

Error handling with JSON in Parse.com causes compatibility issues in Express js 4

I need help figuring out why the data I send in a POST call to an Express JS server hosted on Parse.com is not being received properly. This is how I send the data: var data = new Array(); data["firstName"] = firstName; data["lastName"] = las ...

When using `res.send()`, an error of Type Error may be encountered stating that the callback is not a function. However, despite this error,

I am currently working on a function for my Node.js server, using Express as the framework and MongoDB as the database. This function involves calling two mongoose queries: (1) Retrieving filtered data from one collection (2) Aggregating data from anothe ...

What is the process of retrieving an image file in a Java post API when it is being transmitted as form data through Jquery?

I have encountered an issue with fetching file data in my POST API when utilizing three input file fields in JavaScript. The values are being sent using formdata in jQuery upon clicking the submit button, but I am experiencing difficulties in retrieving th ...

Tips for utilizing ng-checked and ng-disabled in conjunction with ng-repeat

I encountered a challenge with ng-repeat while incorporating ng-checked and ng-disable alongside it. <div ng-repeat="module in modulelist"> <input id="switch{{$index}}" ng-init="setState($index);" type="checkbox" ng-checked="switch.checked" ng-di ...

What is the process for updating the values of all objects within an array of objects using Javascript?

I am attempting to update the values of car in all objects within an array called data with the values from newData. Here is my code snippet: import "./styles.css"; const data = [ { id: 1, car: "Toyota 2020", owner: "BM" }, ...