Ajax request in Rails not receiving a response from the controller

After troubleshooting a simple GET request to the controller action, I confirmed that the request is being made successfully and there are no issues with the controller executing the action. However, I am not receiving any response data.

$.ajax({
  url: _url,
  type: 'GET',
  dataType: 'json',
  sucess: function(response) {
    alert(response);
    console.log("response: " + response);
  }
});
  def get_team_statuses
    @wager = Wager.find(params[:id])
    _team_count = helpers.get_team_member_names_without_self(@wager).count + 1
    _opponent_count = helpers.get_opposing_member_names(@wager).count

    _team_full = _team_count == @wager.team_size.players_count
    _opposing_team_full = _opponent_count == @wager.team_size.players_count

    respond_to do |format|
      format.html
      format.json { render json: {team_full: _team_full, opposing_team_full: _opposing_team_full } }
    end
  end

Despite reviewing various resources and documentation suggesting everything is set up correctly, the only notable message received is:

Started GET "/wagers/1b4b6da7-7dd0-4a42-b17b-3872850d908d/get-team-statuses" for ::1 at 2020-08-10 16:11:01 -0700 Processing by WagersController#get_team_statuses as JSON

[active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (0.09ms)

Completed 200 OK in 12ms (Views: 0.5ms | ActiveRecord: 2.0ms)

Any suggestions or insights?

Edit: Here's what my network tab displays for XHR requests. It shows the multiple request instances when the button was clicked three times.

Answer №1

This solution should work:

$.ajax({
  url: _url,
  type: 'GET',
  dataType: 'json',
  success: function(response) {
    alert(response);
    console.log("response received: " + response);
  }
});

You have a small typo in between success and sucess

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

Express displaying undefined when referring to EJS variable

After receiving valuable assistance from user Jobsamuel, I have been encountering challenges in displaying the data retrieved from an API call on a webpage: // EJS template to show API data. app.get('/activities', function (req, res) { if (re ...

Is there a way to emphasize a particular day on the calendar obtained from the URL?

I have implemented FullCalendar functionality to enable users to select a specific date, retrieve data from a database, and then reload the page with that data. The page is updated with the selected date in the URL. However, when the page reloads, althoug ...

What is the best way to use jQuery to refresh a partial in Ruby and insert it into a specific div element?

One of my web elements is a button that has the following appearance: <%= link_to "Join", "#", :id => "joinleave", :class => "buttonrefresh small join button expand", :'project-id' => @project.id %> Upon clicking this button, I h ...

My website code being stored in cache by Chrome (as well as other browsers)

Issue: I am facing an issue with hosting a widget on my client's website where the widget needs to be different for each page. To display the widget, the client embeds a script tag on their pages. This script is loaded on every page and the content ...

Ending JavaScript promises

I am currently utilizing the Google JS closure library which can be found at https://developers.google.com/closure/library/ Below is the code snippet that I have: if (endDate >= wap.com.ifx.util.IfxComponentUtil.yyyymmdd(currentDate) && goog.o ...

What is the process for submitting a form on consecutive URLs?

I have a form that requires input for settings and includes two buttons: one to save the form and another to both save and execute the settings. <form method="post" action="/settings/{{id}}/save"> <!-- input fields --> ...

How can we identify if the user is utilizing a text-input control?

Incorporating keyboard shortcuts into my HTML + GWT application is a goal of mine, but I am hesitant about triggering actions when users are typing in a text area or utilizing the keyboard for select menu operations. I am curious if there exists a method ...

Changing a CURL request to an AJAX request

Could someone help me convert the CURL request below into HTML? Unfortunately, the application does not provide any AJAX documentation on their website. curl -X GET --header "Accept: application/json" --header "user-key: xxxx" "https://developers.abcdef ...

How does a JS event impact the state transition in a backend state machine built on Rails?

I am currently developing a new project where the backend involves Users who have multiple "Courses" each containing multiple "Steps". My goal is to create a JavaScript function that validates the user's answer. For example, if the user inputs "6", w ...

WebStorm 6 does not recognize the post method in Node.js Express

I recently started learning about node.js and decided to experiment with the express module in my application. Everything was going well until I attempted to use the app.post method. I am developing my app on WebStorm 6.0.2 and it doesn't seem to reco ...

Eliminate unnecessary CSS classes from libraries such as bootstrap when working on a React project

Our team is currently in the process of developing a React project that involves webpack and babel. Our goal is to automatically remove any unused CSS classes from CSS frameworks Bootstrap and AdminLTE 2, which are integral parts of our project. For this ...

Utilizing jQuery to dynamically load content that relies on javascript within a specified div

I came up with a function that can easily add floating resizable content to a webpage: function AddFloatingWindow(id) { var window = document.createElement('div'); $(window).attr('id', id); $(window).height(100) ...

Can transitions be applied to links in this manner?

Having an issue with ajax requests, I am currently resorting to using JavaScript linking. This is how I normally link: window.location.href = ('file:///android_asset/www/custom/kontakty.html'); I am curious if it's possible to add a transi ...

When calling UIComponent.getRouterFor, a TypeScript error is displayed indicating the unsafe return of a value typed as 'any'

I have recently integrated TypeScript into my SAPUI5 project and am encountering issues with the ESLint messages related to types. Consider this simple example: In this snippet of code, I am getting an error message saying "Unsafe return of an any typed ...

Create a Bootstrap modal that includes a checkbox option to prevent it from appearing again in

I am attempting to display a bootstrap modal upon body load based on a value retrieved from a MySQL database. The bootstrap modal is included in the body and shown successfully depending on the database value using the following code snippet: $results ...

How to style text in CSS with a numbered underline beneath

Is there a way to apply underlining to text and include a small number underneath the underline in a similar style shown in this image, by utilizing css, html, or javascript? ...

Can you provide some insight on how to store XMLHttpRequest response in Javascript for future

I have a function in my codebase that is responsible for loading HTML templates asynchronously: loadTemplate: function(url) { return new Promise(function(resolve, reject) { var xhr = new XMLHttpRequest(); xhr.open("GET" ...

AngularJS $scope variable issue

After searching online, I found this code snippet that I tried to implement, but unfortunately, it's not displaying any data. Below is the HTML code: <html data-ng-app=""> <head> <title>Example 4: Using AngularJS Directives an ...

What is the best way to showcase Vue data of a selected element from a v-for loop in a

Here is an example of how my json data is structured. I have multiple elements being displayed in a v-for loop, and when one is clicked, I want to show specific information from that element in a modal. [{ "id": 1, "companyNa ...

Encountered an issue with reading the property childnotes of null during data retrieval using ajax in PHP

Hello, I am encountering an error while trying to fetch data using ajax. The error message is "Cannot read property 'childNodes' of null". Can anyone help me identify what might be wrong with my code? I have created a form to search for data with ...