Jquery Ajax Error 400 Bad Request
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 post 400 bad request angularjs Stack Overflow the company Business Learn more about hiring developers or posting ads with jquery ajax handle 400 us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is 400 bad request ajax spring mvc 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 11 down vote favorite 3 This works
400 Bad Request Post Method
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: function(data) {//do something} ajax jquery share|improve this question edited Nov 400 bad request post json 11 '10 at 17:03 Teja Kantamneni 11k94378 asked Nov 11 '10 at 16:58 Scott B 10k40110204 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 comment| up vote 5 down vote Late answer, but I figured it's worth keeping this updated. Expanding on Andrea Turri ans
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the the server responded with a status of 400 (bad request) workings and policies of this site About Us Learn more about Stack
"networkerror: 400 Bad Request
Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
500 (internal Server Error) Ajax Post
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; http://stackoverflow.com/questions/4156991/jquery-ajax-returns-400-bad-request 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 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 http://stackoverflow.com/questions/16017081/getting-400-bad-request-error-in-jquery-ajax-post/16054639 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 '13 at 14:02 asked Apr 15 '13 at 13:57 blunderboy 10.8k1158104 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 43 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. S
Navigation ← Previous TicketNext Ticket → Opened 5 years ago Closed 5 years ago Last modified 5 years ago https://bugs.jquery.com/ticket/9613 #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: bad request 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? 400 bad request 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