iwanttogoas Posted April 9, 2024 Posted April 9, 2024 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 Quote
ryan1969 Posted April 15, 2024 Posted April 15, 2024 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. Quote
iwanttogoas Posted April 15, 2024 Author Posted April 15, 2024 Thanks - I hadn't changed the header type - will give that a try and see what happens! Quote
ryan1969 Posted April 17, 2024 Posted April 17, 2024 On 4/15/2024 at 4:38 PM, iwanttogoas said: Thanks - I hadn't changed the header type - will give that a try and see what happens! Official Site Ok NP. Best Regard, Ryan1969 Quote
Recommended Posts
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.