Jquery Post 400 Error
Contents |
here for a quick overview of the site Help
400 (bad Request) Ajax Get
Center Detailed answers to any questions you might have Meta post 400 bad request angularjs Discuss the workings and policies of this site About Us Learn more about Stack jquery ajax handle 400 Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
400 Bad Request Ajax Spring Mvc
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 Continually receiving 400 (Bad Request) on jquery ajax post to MVC controller up vote 4 down
400 Bad Request Post Method
vote favorite My ajax call looks like this $.ajax({ //actually approve or reject the promotion url: url, type: "POST", data: '{'+data.PromotionId+','+data.UserId+','+data.ReasonText+'}', dataType: "json", //contentType: "application/json; charset=utf-8", success: function (data) { if (indicator == 'A') { alert('Promotion approved successfully!'); } else { alert('Promotion rejected successfully.'); } var homelink = '<%: Url.Action("Index","Home") %>'; window.location.href = (homelink); returndata = data; }, error: function (xhRequest, ErrorText, thrownError) { alert("Failed to process promotion correctly, please try again"); console.log('xhRequest: ' + xhRequest + "\n"); console.log('ErrorText: ' + ErrorText + "\n"); console.log('thrownError: ' + thrownError + "\n"); } }); And my MVC controller looks like this: [HttpPost] public HttpResponseMessage ApprovePromotion(PromotionDecision decision) { if (ModelState.IsValid && decision != null) { bool status = PromotionBo.ApprovePromotion(decision); if (status == true) return new HttpResponseMessage(HttpStatusCode.OK); } return new HttpResponseMessage(HttpStatusCode.BadRequest); } I had thought the syntax was correct on both of these however ever
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss 400 bad request post json the workings and policies of this site About Us Learn more
Http Post Bad Request
about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow networkerror 400 bad request 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 http://stackoverflow.com/questions/14281537/continually-receiving-400-bad-request-on-jquery-ajax-post-to-mvc-controller each other. Join them; it only takes a minute: Sign up jQuery.post returns 400 bad request error [rails] up vote 0 down vote favorite I am using rails 4 and balanced.js and am trying to post the returned token to the back end using jQuery.post. I have the correct url getting passed but receive a 400 error. TO http://stackoverflow.com/questions/25129977/jquery-post-returns-400-bad-request-error-rails CLARIFY: I am getting an error on the jquery.ajax after receiving a valid token from balanced. jQuery -> $('#cc-submit').click (e) -> e.preventDefault() handleResponse = (response) -> if (response.status_code == 201) fundingInstrument = (if response.cards? then response.cards[0] else response.bank_accounts[0]) alert(fundingInstrument.href) $('#tablecharge_uri').val(fundingInstrument.href) url = '/events/' + urlid + '/tablecharges' alert(url) jQuery.ajax({type: "POST", url: url, data: {uri: fundingInstrument.href, event_id: urlid}, sucess: (data) -> alert data.id error: (data) -> alert "not cool"}) else alert(response.status + JSON.stringify(response, false, 1)) payload = { name: $('#cc-name').val() number: $('#cc-number').val() expiration_month: $('#cc-expiration-month').val() expiration_year: $('#cc-expiration-year').val() ccv: $('#cc-ccv').val() } balanced.card.create(payload, handleResponse) here is my controller: class TablechargesController < ApplicationController def new @event = Event.find(params[:event_id]) @table = @event.tablecharges.build end def index @event = Event.find(params[:event_id]) @table = @event.tablecharges.all end def create @event = Event.find(params[:event_id]) @table = @event.tablecharges.build(table_charge_params) respond_to do |format| format.js { render json: 'Your message', status: :ok } end if @table.save redirect_to @event, :notice => "Thanks for the cash" else render :new end end private def table_charge_params params.require(:tablecharge).permit(:name, :email) end end here is my model: class Tablecharge < ActiveRecord::Base belongs_to :event attr_accessor :cc_name attr_access
and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor. Announcement Announcement Module Collapse No announcement yet. Spring http://forum.spring.io/forum/spring-projects/web/126470-spring-mvc-rest-post-call-is-giving-400-with-jquery-ajax-call MVC REST POST call is giving 400 with JQuery ajax call Page https://github.com/WP-API/WP-API/issues/119 Title Module Move Remove Collapse X Conversation Detail Module Collapse Posts Latest Activity Search Forums Page of 1 Filter Time All Time Today Last Week Last Month Show All Discussions only Photos only Videos only Links only Polls only Filtered by: Clear All new posts mleejr Junior Member Join bad request Date: May 2007 Posts: 13 #1 Spring MVC REST POST call is giving 400 with JQuery ajax call Apr 2nd, 2013, 01:13 PM I am trying to call my spring MVC REST service and it works with a JQuery $.post but not $.ajax. The javascript shows this 400 error; 1. Failed to load resource: the server responded with a status 400 bad request of 400 (Bad Request) https://s3.amazonaws.com/codiqa-cdn/jquery-1.7.2.min.js 1. sendjquery-1.7.2.min.js:4 2. f.extend.ajaxjquery-1.7.2.min.js:4 3. logIntoCMS:8080/coco/:124 4. onclick And in spring it gives this error; DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.ExceptionHandlerExceptionResolver - Resolving exception from handler [public com.company.User com.company.SessionController.login(java.lang.Stri ng,java.lang.String,java.lang.String,java.lang.Str ing,org.springframework.ui.Model)]: org.springframework.web.bind.MissingServletRequest ParameterException: Required String parameter 'password' is not present In JQuery this code works; Code: var paramsData = {password:$('password').val(), authorizationType: $('authorizationType').val()}; $.post(buildURL, paramsData, function(data){ user = data }); But this doesn't; Code: $.ajax({ type: "POST", url: buildURL, data: JSON.stringify({ password: $('#password').val(), authorizationType: $('#authorizationType').val() }), contentType: "application/json; charset=utf-8", dataType: "json", async: false, success: function(data) { user = data; } }); The spring code is the same for both calls; Code: @RequestMapping(value="/{cms}/{username}", method=RequestMethod.POST) public @ResponseBody User login(@PathVariable("cms") String cmsName, @PathVariable("username") String username, @RequestParam("password") String password, @RequestParam("authorizationType") String authorizationType, Model model) { ....it never reaches the first line in the method... The only real difference is I need it to be synchronous to wait on user data so I need $.ajax with async:false. It looks like the data line is wrong in the ajax call. The data comes from an input field and select box both with the IDs a
Sign in Pricing Blog Support Search GitHub This repository Watch 258 Star 3,611 Fork 665 WP-API/WP-API Code Issues 67 Pull requests 13 Projects 1 Pulse Graphs New issue 400 Bad Request: Translate CURL to jquery.ajax() #119 Closed landwire opened this Issue Mar 17, 2014 · 1 comment Projects None yet Labels None yet Milestone No milestone Assignees No one assigned 2 participants landwire commented Mar 17, 2014 Sorry to post this as a new issue, but I am totally stuck with authorisation via an ajax call. I posted this under another issue a month ago, but never got a reply. I am making this curl call and it works great (NO ERRORS) now after installing the WP BASIC Auth as mentioned in this ticket #66. That info could really go into the Basic Usage documentation! curl --data '{"title": "Hello Updated new post with cats!"}' -H "Content-Type: application/javascript" --user username:password http://apitest.landwire.net/wordpress/wp-json.php/posts/1 How can I write that curl as jquery ajax? I tried all sorts of variations of the below: // extra function function setAuthHeader(xhr){ var creds = username + ':' + password; var basicScheme = btoa(creds); var hashStr = "Basic "+basicScheme; xhr.setRequestHeader('Authorization', hashStr); } // NOT works function editPost(id) { if(id) { var the_url = 'http://apitest.landwire.net/wordpress/wp-json.php/posts/'+ id; } else { return; } jQuery.ajax({ url: the_url, //headers: { //'Authorization': "Basic " + btoa("username" + ":" + "password"), // 'Content-Type': 'application/javascript' //}, //headers: { // "HTTP:Authorization": "Basic " + btoa("username:password") //}, //username: 'apitest', // password: 'password', //beforeSend: function(xhr) { //xhr.setRequestHeader("Authorization", "Basic " + btoa("username" + ":" + "password")); }, // beforeSend: function(xhr) { // xhr.setRequestHeader("Authorization", "Basic " + //btoa("username:password")); // }, beforeSend: function(xhr) { xhr.setRequestHeader('Authorization', hashStr); }, data: { 'title': 'Hello Updated MANAN World!', //'username': 'username', //'password': 'password' }, dataType: 'json', 'Content-Type': 'application/json', //also tried application/javascript type: 'PUT', success: function(data, textStatus, jqXHR){ console.log('post creation success! ' + textStatus); var json_response = data; console.log('Updated Post ID ' + id + ': ', data); }, error: