Why does data travel through the URL during an AJAX POST request?

Upon making an Ajax Post, the error I encountered is as follows: 414 Request-URI Too Large

I am confused as to why the data is being sent over the URL and not just in the body. In Chrome, I can see the param1 data in the request URL, query string parameters, and in the request payload. How do I remove it from the URL?


routes = JSON.stringify(routes);
$.ajax({
        type: "POST",
        url: "http://127.0.0.1:3000/s",
        data: {
          param1: routes
        },
        success: function(data) {
          $('div.home-products').html(
            data);
        }
      });

This is the entire routes object after stringify:

{big JSON object with various details}

Shown below are details from the Chrome network:

Request URL: URL that exceeds character limit due to large amount of data Request Method: POST Status Code: 414 Request-URI Too Large Remote Address: 127.0.0.1:3000 Referrer Policy: no-referrer-when-downgrade Response Headers... Request Headers... Query String Parameters... Form Data...

Answer №1

Here's a suggestion that might help in your situation:

Extract the base URL from window.location.href by removing any query parameters:
url: window.location.href.replace(/\?.*$/, ''),

By stripping off any get parameters, you can ensure that unnecessary information is not included when making requests. It's possible that the presence of certain get parameters like view-grid could be causing issues with how ajax handles POST parameters.

Answer №2

The solution ended up being the absence of the contentType: "json" parameter.

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

It appears that Yarn is having trouble properly retrieving all the necessary files for a package

Recently, I encountered a strange issue in our project involving 3 microservices, all using the exceljs library. Two of the microservices successfully download all necessary files for this package through yarn. However, the third microservice is missing ...

Refreshing a partial view dynamically with JsonResult - the complete guide

Within my View, there is a ribbon with a spinner that allows users to select an int type which serves as a parameter for retrieving data from the repository. To accomplish this, I initiated an ajax request: var url = "/ControllerExample/GetJsonUrl?para ...

Is it feasible to impersonate a session in PHP by manipulating cookies on the client-side with JavaScript?

Is it possible for an unauthorized visitor to view, delete, or edit session cookies in a PHP web app if HttpOnly cookies are not being used? What happens when a user on a non-session page of a web app sets a cookie with the same name as a session page coo ...

What are some methods for displaying images retrieved from an API onto an HTML webpage?

Problem: The image is not appearing on my HTML page. How can I fix this issue? Please see below for details. https://i.sstatic.net/XYoHg.png Here are the code snippets I am using to display the image: <div class="col-md-7"> <div c ...

Utilizing a dictionary for comparing with an API response in order to generate an array of unique objects by eliminating duplicates

I currently have a React component that utilizes a dictionary to compare against an API response for address state. The goal is to map only the states that are returned back as options in a dropdown. Below is the mapping function used to create an array o ...

The axios test in jest successfully passes despite encountering a Network Error advisory

Within my utils class, I have implemented axios for handling basic REST calls. While running a jest unit test, the tests pass successfully but an advisory error pops up: C:/home/dev/node_modules/axios/lib/core/createError.js:16 var error = new Error(messag ...

What could be causing the discrepancy in results between the first and second methods?

Implementing Weather Icons: const getWeatherIcon = (iconParameter) => { const icon = `https://openweathermap.org/img/wn/${iconParameter}@2x.png` return <img src={icon} alt={iconParameter} /> } <div className="weathericon"> ...

Tips for decoding the excel PRODUCT function

Seeking help to convert the =(1-PRODUCT(K5:K14)) Excel formula into JavaScript code. I attempted to write the code based on my own understanding, but the result is not what I expected. exp_PRODUCT= [ 0.993758608, 0.993847362, 0.993934866, 0.99402 ...

Using Three.JS 'OrbitControls' in VueJS application results in a black screen appearing?

Currently, I've been delving into the basic cube exercise on Three.js, and incorporating the three.js cube into my Vue.JS application. Initially, everything was functioning smoothly, with my cube rotating as intended using animate, etc. However, thi ...

I'm having trouble getting the infoWindow to function properly

As someone who is new to JavaScript, I recently came across a question on Google Maps JS API v3 - Simple Multiple Marker Example and attempted to implement the solution provided by Daniel Vassallo. var Australia = new google.maps.LatLng(-27.16881, 132.7 ...

Analyze the individuals listed in one column of the table and calculate the total from the adjacent column using JavaScript

I have a table with participant data that I would like to compare. If a participant has multiple result points in the table, I want a script to calculate the sum of all their results. This process should be repeated for each participant listed in the table ...

npm issue: unnecessary package: [email protected]

Hi there! I'm currently in the process of learning how to build a website using node.js. At the moment, I have node v4.5.0, npm 2.15.9, and coffeescript 1.10.0 all installed on my system. Following along with the instructions from a book called "Coffe ...

Trouble arises when trying to invoke a prototype function using setInterval

Having created a prototype class for Bot, I encountered an issue. Upon calling the init() function after its creation, it correctly alerts "a 5000". However, when the prototype function calls getUpdates(), it fails to reach the value of "this" and instead ...

The AJAX call using DataTables version 1.10.6 returned an error, requesting an unknown parameter 0 for the first row

I recently started using DataTables and initially had it working smoothly until I decided to switch to server-side processing. It seems like I'm getting closer to making it work properly, as it now shows me an error message and displays the correct n ...

Unable to send PHP Mailer to recipient; however, it is successfully sending to the form filler

I've been struggling to fix this issue for days and now I'm reaching out for help. The form I'm using is based on a script I found here. Everything seems to be working fine with the form, except that when I test it, the email is sent to th ...

trigger an event from a different event in Node.js

I am attempting to retrieve the list of newly connected users in admin.html client.html (client login authentication) admin.html (notify new user join) server.js app.get('/', function(req, res){ res.sendfile('client.html'); }); ap ...

Verify the functionality of the input fields by examining all 6 of them

I'm facing a challenge with a validation function in my project that involves 6 input fields each with different answers. The inputs are labeled as input1 to input6 and I need to verify the answers which are: 2, 3, 2, 2, 4, and 4 respectively. For e ...

Remove the link to a file that was uploaded with the help of angular

I have created a script in AngularJS for uploading files which successfully uploads the files to a folder. However, I am facing an issue where removing a file from the queue does not delete the file from the folder. Can anyone suggest how to unlink or re ...

Changing the <title> tag in JavaServer Faces 2 with PrimeFaces 3.3.1

Can the text within the <title> tag be updated periodically on a webpage? Is there a way to achieve this using <p:poll>, or is a complete page refresh necessary? I am looking to show a value from my backend bean. Thank you in advance for any a ...

Navigate through a given value in the event that the property undergoes a name change with each

Exploring an example found on the JSON site, I am facing a situation where I am using an API with JSON data. The property name "glossary" changes for each request made. For instance, if you search for "glossary", the first property is glossary. However, if ...