Network Error 400 Bad Request Ajax
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us jquery ajax handle 400 Learn more about Stack Overflow the company Business Learn more about hiring developers
400 Bad Request Ajax Spring Mvc
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack
Post 400 Bad Request Angularjs
Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up jQuery.ajax returns 400 Bad Request up vote
400 Bad Request Post Method
11 down vote favorite 3 This works fine: jQuery('#my_get_related_keywords').click(function() { if (jQuery('#my_keyword').val() == '') return false; jQuery.getJSON("http://boss.yahooapis.com/ysearch/web/v1/" +jQuery('#my_keyword').val()+"?" +"appid=myAppID" +"&lang=en" +"&format=json" +"&count=50" +"&view=keyterms" +"&callback=?", function (data) {//do something} This returns 400 Bad Request (Just a reformulation of the above jQuery using .ajax to support error handling). jQuery('#my_get_related_keywords').click(function() { if (jQuery('#my_keyword').val() == '') return false; jQuery('#my_loader').show(); jQuery.ajax( { url: "http://boss.yahooapis.com/ysearch/web/v1/" +jQuery('#my_keyword').val()+"?" +"appid=myAppID" +"&lang=en" +"&format=json" +"&count=50" +"&view=keyterms" +"&callback=?", success: the server responded with a status of 400 (bad request) function(data) {//do something} ajax jquery share|improve this question edited Nov 11 '10 at 17:03 Teja Kantamneni 11k94378 asked Nov 11 '10 at 16:58 Scott B 10.1k40110204 do you have to add method (post or get) somewhere? –Jan Nov 11 '10 at 17:02 add a comment| 3 Answers 3 active oldest votes up vote 11 down vote accepted is not correct.. so correct way is below: $('#my_get_related_keywords').click(function() { $.ajax({ type: "POST", url: "HERE PUT THE PATH OF YOUR SERVICE OR PAGE", data: '{"HERE YOU CAN PUT DATA TO PASS AT THE SERVICE"}', contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { //do something }, error: function (errormessage) { //do something else } }); } share|improve this answer answered Nov 11 '10 at 17:05 Andrea Turri 4,65662552 Thanks for the quick help Toro. @light was correct too. –Scott B Nov 11 '10 at 17:30 add a comment| up vote 9 down vote Add this to your ajax call: contentType: "application/json; charset=utf-8", dataType: "json" share|improve this answer answered Nov 11 '10 at 17:03 light 646414 Thanks. That was it. @Toro just beat you to it :) –Scott B Nov 11 '10 at 17:30 add a commen
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us 400 bad request post json Learn more about Stack Overflow the company Business Learn more about hiring developers "networkerror: 400 bad request or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack failed to load resource: the server responded with a status of 400 Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “400 Bad Request” response for AJAX request http://stackoverflow.com/questions/4156991/jquery-ajax-returns-400-bad-request up vote 6 down vote favorite 1 I have the following jQuery AJAX request: // collect form data and create user obj var user = new User(); user.firstname = $("#usrFirstName").val(); user.lastname = $("#usrSurname").val(); user.role = $("#usrRole").val(); // actual ajax request $.ajax({ type: 'POST', url : 'http://awesome-url', crossDomain: true, data: user, contentType:"application/json; charset=utf-8", dataType: 'json' }).done(function(data, status) { alert(JSON.stringify(data)); }).fail(function(data, status) { alert(status); alert(JSON.stringify(data)); }); The response from http://stackoverflow.com/questions/19546866/400-bad-request-response-for-ajax-request the Server is: "status":400,"statusText":"Bad Request" "The request sent by the client was syntactically incorrect." The server is running Spring-MVC. But as far as I can tell it is working correctly. Because if I'm sending a request manually with Postman and the following configuration it works. Header: Content-Type application/json; charset=utf-8 Content: {"firstname":"alex","lastname":"lala","role":"admin"} I have to mention that it is a cross-domain request (for the time developing, it will be hosted on the same domain as the server later). I did disable the security settings in the browser and AJAX requests to the server are working fine (as long as I don't have to send data). javascript jquery spring-mvc share|improve this question asked Oct 23 '13 at 16:09 rob 82341126 What happens when you form that same exact request in a browser-based REST tool and submit it? Have you tried to stringify your User object before sending? –Mike Brant Oct 23 '13 at 16:14 If the server doesn’t like the data it receives, then you should ask the server why – meaning, log what request is actually coming in, check log files, etc. –CBroe Oct 23 '13 at 16:17 I just tried stringify and i
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about http://stackoverflow.com/questions/35900226/ajax-call-gets-a-400-bad-request-response-from-my-rest-api Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up AJAX call gets a “400 bad request” response from my REST API up bad request vote 0 down vote favorite AJAX call gets a "400 bad request" response from my REST API. Here is the JavaScript: var client_id = 'xxxxxx'; var client_secret = 'yyyyyy'; var username = document.getElementById("inputUsername").value; var password = document.getElementById("inputPassword").value; var params = { client_id: client_id, client_secret: client_secret, grant_type: 'password', username: username, password: password }; var successCallback = function(data, textStatus, jqXHR) { console.log('Success: ', textStatus); }; var errorCallback = function(jqXHR, textStatus, errorThrown) { 400 bad request console.log('Error: ', jqXHR.status, textStatus, errorThrown); }; var completeCallback = function(jqXHR, textStatus) { console.log('Complete: ', textStatus); }; $.ajax({ traditional: true, type: 'POST', url: 'http://127.0.0.1:8000/auth/token', contentType: 'application/json', dataType: 'json', data: params, success: successCallback, error: errorCallback, complete: completeCallback }); I also tried setting the data using the following, but I got the same response: var data = jQuery.param(params); ...with the corresponding change to the ajax call: $.ajax({ ... data: data, ... }); I want to achieve the same result as using a curl command: curl -X POST "http://127.0.0.1:8000/auth/token" -d "client_id=xxxxxx&client_secret=yyyyyy&grant_type=password&username=aaaaaaa&password=bbbbbb" javascript jquery ajax rest share|improve this question asked Mar 9 at 18:54 tyebillion 505317 3 Open the developer tools in your browser. Look at the request you are actually making in the Network tab. Look at any error messages that are reported in the Options tab. Odds are that you are failing to handle the preflight on your server. –Quentin Mar 9 at 18:56 1 Thank you. After reading about the preflight options in the content section of the ajax page in the jquery manual I was able to fix the problem. –tyebillion Mar 9 at 19:06 It is worth noting that calling an OAuth based REST API from JavaScript is insecure. So this is n