Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Posted

Hi,

I have a custom widget that uses get-widget/one/ to refresh itself on the screen after user input and it is working fine.  But I have had to add a comment box to it which means that the amount of data being passed back may no be too big for a GET request. 
As soon as I changed it to send as a POST I started getting back 400 - bad request with a response of "please contact us if you see this page"
 

I have put some debugging in and it looks like it is no longer getting as far as GetWidgetController,  as soon as I change it back to GET it works fine.  

Any help would be appreciated!

Thanks
Steve

Posted
On 4/9/2024 at 7:56 PM, iwanttogoas said:

Hi,

I have a custom widget that uses get-widget/one/ to refresh itself on the screen after user input and it is working fine.  But I have had to add a comment box to it which means that the amount of data being passed back may no be too big for a GET request. 
As soon as I changed it to send as a POST I started getting back 400 - bad request with a response of "please contact us if you see this page"

 

I have put some debugging in and it looks like it is no longer getting as far as GetWidgetController,  as soon as I change it back to GET it works fine.  

Any help would be appreciated!

Thanks
Steve

Hello, 

 

A 400 Bad Request error when switching from a GET to a POST request usually indicates that there’s an issue with the way the data is being sent or received. Here are a few things you can check and try:

Content-Type Header: Ensure that you’re setting the Content-Type header to application/x-www-form-urlencoded or application/json, depending on how you’re encoding your data.

Data Serialization: If you’re sending JSON data, make sure to stringify your JSON object before sending it. For example:
 

data: JSON.stringify(yourDataObject)
 

Request Payload: Verify that the data you’re sending in the POST request matches the expected format of the server endpoint. If there’s a mismatch, the server might reject the request.
Server-Side Handling: Check the server-side code (GetWidgetController) to ensure it’s correctly configured to handle POST requests and that it’s not expecting parameters only from the query string.
Error Handling: Implement error handling on the server side to provide more informative error messages. This can help you pinpoint the exact cause of the issue.
Debugging Tools: Use network debugging tools to inspect the HTTP request and response. Tools like Postman or browser developer tools can show you the headers, payload, and response body which can be very helpful.

Here’s a sample AJAX POST request for reference:

$.ajax({
  type: 'POST',
  url: 'yourEndpoint',
  data: JSON.stringify({ comment: 'Your comment here' }),
  contentType: 'application/json',
  success: function(response) {
    // Handle success
  },
  error: function(xhr, status, error) {
    // Handle error
  }
});

 

 

Remember to replace 'yourEndpoint' with your actual endpoint and the data object with your actual data to be sent.

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...