There is an issue with reading the model sent to the view during an ajax get request

Could use some assistance with the following:

I am working on a function that is supposed to return two different entities, one as a return value and the other as a model. The return can be read, but the model cannot.

$('.thumbnail').click(function(event){
  var id=($(this).data("targetelement"));
  var url='getphotos/'+id;
  $.get(url,function(data, textStatus, jqXHR){
      /*<![CDATA[*/
          var product = /*[[${message}]]*/
      /*]]>*/
          console.log(product);

  });

});

This controller looks like this:

@GetMapping(value = "getphotos/{id}")
public @ResponseBody ArrayList<Gallery> getPhotos(@PathVariable int id, Model model, HttpServletRequest req) {
    Product pro=service.getProduct(id);
    model.addAttribute("pro", pro);
    return service.getphotos(id);
}

Answer №1

Accessing the model directly is restricted. One workaround is to include the model attribute in the mapping responsible for rendering the view, utilize Thymeleaf to process it, and fetch photos using AJAX for further processing. Alternatively, you can combine both objects into a map and return this map. Subsequently, use AJAX and JavaScript to handle processing of these objects.

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

Modifying table background color using AJAX and jQuery?

Scenario: My web page is designed to automatically search for a specific cell input by the user. If the cell has been input with a value, the table's background color will turn red; otherwise, it will remain green. Currently, the table has not been p ...

Quick tip on closing an Angular-ui modal from a separate controller

I am currently using Angular-ui to display a modal with a form inside. Here is the code snippet: app.controller('NewCaseModalCtrl', ['$http', '$scope','$modal', function ($http, $scope, $modal, $log) { $scope.ite ...

Utilizing HTML5 Canvas for Shadow Effects with Gradients

Surprisingly, it seems that the canvas API does not support applying gradients to shadows in the way we expect: var grad = ctx.createLinearGradient(fromX, fromY, toX, toY); grad.addColorStop(0, "red"); grad.addColorStop(1, "blue"); ctx.strokeStyle = gra ...

Ways to limit Javascript math results to two decimal points and erase previous output in one go

Working on a JavaScript multiplication task. The input provided is multiplied by 0.05. The JavaScript code successfully multiplies the input number by 0.05, but encounters some issues: The calculated value should be rounded to two decimal points. For ex ...

Discover the class name within the AJAX content

I have a unique ajax response generated by a server-sided script: <div class="item-title3">Testname</div> <div class="item-level">120</div> <div class="item-binding">40</div> <div class=& ...

How to create a looping animation effect for a div using CSS on hover

Using Bootstrap framework with Wordpress site .test { position: absolute; z-index: 9; left: 50%; height: 10em; width: 10em; margin-left: -5em; background-size: cover; opacity: 0; transition: opacity 0.5s ease; transform: translateY(- ...

Tips on sending an image to a WebMethod through jQuery

I have a WebMethod in ASP.NET that looks like this. [WebMethod] public static void AddCameraImage(string imageArray) { //do something } Currently, I am trying to read an image from a canvas element and then POST it to the above met ...

Personalizing the look of Stripe Payment Component in a React Application

Currently, I have integrated the Stripe Payment Element into my React application using the code snippet below: import { useStripe, useElements, PaymentElement, } from '@stripe/react-stripe-js' export const PaymentDetails = () => { const st ...

JavaScript slowness

Currently, I am developing a test page that consists of buttons triggering various scripts. One of the functionalities I am trying to implement is changing the background color every second for 5 seconds, cycling through a total of 5 different colors. Desp ...

Guide on using jQuery Ajax to send form data to another cs file in ASP.Net

How can I create a form to submit data to another CS file in order to update the database. Below is the form and corresponding code. <form id="form1" runat="server" action="./update.aspx" class="col-md-10"> <asp:Table ID="GridView1" class= ...

What is the best way to integrate Google Analytics into a Next.js application without the need for an _app.js or _document.js file?

I'm encountering some challenges while trying to incorporate Google Analytics into my Next.js application. One issue I'm facing is the absence of an _app.js or _document.js file in the project structure. Additionally, I notice that when I include ...

Are there any resources available to ensure my jQuery script is compatible with multiple browsers?

After realizing that Internet Explorer does not support certain selectors in jQuery, I began to question how to ensure my code will function properly during the writing process. As a Linux user, my testing options are limited to Chrome and Firefox. Is ther ...

Place the child's text within the matching parent data element

I'm having trouble assigning the text values of children to their respective parent's data element, as all the values are being combined. Here is my code: HTML <ul> <li class="item" data-v="1"> <div class="xyz" data-v="2"> ...

Leveraging ng-transclude and the require attribute for effective communication between directives

I'm working with two directives, let's call them: angular.module('app').directive('directiveX', directiveX); function directiveX(){ return { restrict: 'E', transclude: true, ...

What is the method for extracting the value of a JavaScript variable using the .Net framework or C# programming language?

Looking at the code snippet below, I am trying to extract the values of title and videoId. These elements are part of the session, which is nested within units. I am unsure how to retrieve their values using C# or the .Net framework. Can anyone help m ...

Can an array of parameters be utilized in Polymer to initiate an iron-ajax request?

Imagine having an array of parameters, Array1, containing a list of IDs. These IDs will be used as parameters for an AJAX call to the same URL. The goal is to extract information from the AJAX call and store it in a common array, Array2, before moving on t ...

Making an "associated" route the active route within Aurelia

In my Aurelia application, I have implemented two routes: a list route called Work and a detail route called WorkDetail. Currently, only the list route is visible in the navigation menu: Home | *Work* | Contact | . . . When users navigate to the W ...

Send form based on the outcome of the ajax request

I have developed a form that triggers an ajax request upon submission to check the validity of the data. My goal is to automatically submit the form if the ajax response confirms the data is valid, and prevent the form submission if the data is invalid. $ ...

Guide to verifying a Django form with AngularJs

I have a very simple form with 1 field and a submit button. I want to implement validation such that the submit button is disabled when the field is empty and enabled when it is not. I am trying to achieve this dynamically using AngularJs but seem to be mi ...

Having trouble connecting retrieved database information with AngularJS for display in the view

I am currently working on extracting data from a database and displaying it in a view using AngularJS. I have created a WEM method for this purpose: [WebMethod] public static string fetchNames() { SqlHelper sql = new SqlHelper(); DataTable dt = sql.Ex ...