Ajax Bad Request Error
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 Learn more about Stack Overflow the company
Ajax Post Bad Request
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions ajax error 400 bad request Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers,
Jquery Ajax Bad Request
just like you, helping each other. Join them; it only takes a minute: Sign up Getting 400 bad request error in Jquery Ajax POST up vote 23 down vote favorite 12 I am trying to send post 400 bad request angularjs an Ajax POST request using Jquery but I am having 400 bad request error. Here is my code: $.ajax({ type: 'POST', url: "http://localhost:8080/project/server/rest/subjects", data: { "subject:title":"Test Name", "subject:description":"Creating test subject to check POST method API", "sub:tags": ["facebook:work", "facebook:likes"], "sampleSize" : 10, "values": ["science", "machine-learning"] }, error: function(e) { console.log(e); } }); It Says: Can not build resource from request. What am I missing ? jquery ajax post http-status-code-400 share|improve this question edited Apr 15 jquery ajax handle 400 '13 at 14:02 asked Apr 15 '13 at 13:57 blunderboy 10.6k1058103 Preliminary check: your browser is pointed to localhost:8080, right? –Sébastien Renauld Apr 15 '13 at 14:00 1 maybe not what is causing your issue, but it looks like ["facebook:work, facebook:likes"] should be ["facebook:work", "facebook:likes"] –smerny Apr 15 '13 at 14:01 Are you using Java and Jersey perhaps? –Henrik Andersson Apr 15 '13 at 14:01 I am using JAVA not Jersey..Sling servlet at backend. –blunderboy Apr 15 '13 at 14:02 add a comment| 2 Answers 2 active oldest votes up vote 42 down vote accepted Finally, I got the mistake and the reason was I need to stringify the JSON data I was sending. I have to set the content type and datatype in XHR object. So the correct version is here: $.ajax({ type: 'POST', url: "http://localhost:8080/project/server/rest/subjects", data: JSON.stringify({ "subject:title":"Test Name", "subject:description":"Creating test subject to check POST method API", "sub:tags": ["facebook:work", "facebook:likes"], "sampleSize" : 10, "values": ["science", "machine-learning"] }), error: function(e) { console.log(e); }, dataType: "json", contentType: "application/json" }); May be it will help someone else. share|improve this answer edited Apr 17 '13 at 9:58 answered Apr 17 '13 at 8:01 blunderboy 10.6k1058103 4 Could've saved myself an hour of frustrated debugging if I'd found this to begin with. Thanks ;) –bugsdugga
here for a quick overview of the site Help Center Detailed answers to
400 Bad Request Ajax Spring Mvc
any questions you might have Meta Discuss the workings and post 400 error policies of this site About Us Learn more about Stack Overflow the company Business Learn
400 Bad Request Post Method
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 http://stackoverflow.com/questions/16017081/getting-400-bad-request-error-in-jquery-ajax-post Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “400 Bad Request” response for AJAX request up vote 6 down vote favorite 1 I have the following jQuery AJAX request: // collect form data and http://stackoverflow.com/questions/19546866/400-bad-request-response-for-ajax-request 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 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 s
Gherkin Git Go Groovy Haml Handlebars Haskell HTML HTTP Ini iOS Jade Java Javascript jQuery JSON Julia Keyman LaTeX Linux Less LOLCODE Makefile Markdown MATLAB MySQL NASM https://codedump.io/share/wmK1lmAbjXAV/1/getting-400-bad-request-error-in-jquery-ajax-post Node.js NSIS Objective-C Pascal Perl PHP PHP Extras PowerShell Python R React JSX reST (reStructuredText) Rip Ruby Rust SAS Sass (Sass) Sass (Scss) Scala Scheme Smalltalk Smarty SQL Stylus Swift https://bugs.jquery.com/ticket/9613 Twig TypeScript Vb.net VHDL Wiki markup YAML Other Search blunderboy - 7 months ago 1000x Javascript Question Getting 400 bad request error in Jquery Ajax POST I am trying to send bad request an Ajax POST request using Jquery but I am having 400 bad request error. Here is my code: $.ajax({
type: 'POST',
url: "http://localhost:8080/project/server/rest/subjects",
data: {
"subject:title":"Test Name",
"subject:description":"Creating test subject to check POST method API",
"sub:tags": ["facebook:work", "facebook:likes"],
"sampleSize" : 10,
"values": ["science", "machine-learning"]
},
error: function(e) {
console.log(e);
}
});
It Says: Can not build resource from request. What am I missing ? blunderboy Answer Email {} Share Finally, I got the mistake and the reason was I need to stringify the JSON data I was sending. I have to set the content type and datatype in XHR object. So the correct version is here: $.ajax({ type: 'POST', url: "http://localhost:8080/project/server/rest/subjects", data: JSON.stringify({ "subject:title":"Test Name", "subject:description":"Creating test subject to check POST method API", "sub:tags": ["facebook:work", "facebook:likes"], "sampleSize" : 10, "values": ["science", "machine-learning"] }), error: function(e) { console.log(e); }, dataType: "json", contentType: "application/json" }); May be it will help someone else. Source (Stackoverflow) http://stackoverflow.com/questions/16017081/getting-400-bad-request-error-in-jquery-ajax-post Comments Please enable JavaScript to view the comments powered by Disqus. × Email codedump link for Getting 400 bad request error in Jquery Ajax POST Email has been send. To emailaddress: To name: From name: Extra information in the email body (optional): Email: I am sending you the codedump of Getting 400 bad request error in Jquery Ajax POST that you can see here: https://codedump.io/share/wmK1lmAbjXAV/1 Close Send email Share Sign up Sign up with GitHub Email: Displa
Navigation ← Previous TicketNext Ticket → Opened 5 years ago Closed 5 years ago Last modified 5 years ago #9613 closed bug (invalid) $.ajax is not launching error callback on 400 Bad Request when jsonp request is made Reported by: Somebi Owned by: Priority: low Milestone: 1.next Component: ajax Version: 1.6.1 Keywords: neededdocs Cc: jaubourg Blocked by: Blocking: Description Here is sample http://jsfiddle.net/pLuPb/ Here is working sample: http://jsfiddle.net/XVGH9/1/ Thanks ;) Oldest first Newest first Threaded Comments only Change History (3) comment:1 Changed 5 years ago by timmywil Cc jaubourg added Component changed from unfiled to ajax Priority changed from undecided to low Status changed from new to open Confirmed. Can we detect 400s with jsonp tho? comment:2 Changed 5 years ago by jaubourg Keywords needsdocs added Resolution set to invalid Status changed from open to closed What I don't understand is why the doc says "Note: Prior to jQuery 1.5, this handler was not called for cross-domain script and JSONP requests" while the correct sentence is "Note: this handler IS not called for cross-domain script and JSONP requests" ;) So, yes, the answer is no. jQuery doesn't detect HTTP errors for cross-domain script and jsonp requests as is (should be) documented. comment:3 Changed 5 years ago by addyosmani Keywords neededdocs added; needsdocs removed Docs updated: http://api.jquery.com/jQuery.ajax/ Note: See TracTickets for help on using tickets. Download in other formats: Comma-delimited Text Tab-delimited Text RSS Feed Context Navigation Next Ticket → Copyright 2013 The jQuery Foundation Hosting provided by Media Temple CDN provided by MaxCDN Download Documentation Tutorials Bug Tracker Discussion