When ajax call a controller, does it pass the parameter by header or body ?

 In a typical AJAX call to a Java controller, data is usually sent in the body of the request, not as headers. Request headers usually contain metadata about the request, such as information about the client, type of content received, authentication token, etc.

The data you want to send to the server, such as form data or JSON payload, is usually included in the request body. This is usually done using the data property in AJAX calls, especially when using POST or PUT requests.

$.ajax({ url: "your-java-controller-url", type: "POST", data: { key1: "value1", key2: "value2" // Add more key-value pairs as needed }, success: function(response) { // Handle the response from the server }, error: function(error) { // Handle errors } });

In this example, the data attribute contains the key-value pair that will be sent to the request body. The type property specifies the HTTP method and the url property specifies the endpoint (Java controller) that the AJAX call is targeting.

Post a Comment

0 Comments