Jquery Ajax POST not working. works fine for GET

I am trying to post jquery Ajax request but it does not go to my MVC controller.

$.ajax({ url : contextPath + "/check/panelnumber", type : "POST", contentType : "application/json", data :{ "execution" : execution, "panelNumber" : panelNumber }, });

Spring MVC controller

@Controller @RequestMapping("/check") public class ValidateFieldValueController extends FlowEnabledBaseController { @RequestMapping(value = "/panelnumber", method = RequestMethod.POST) public ResponseEntity<String> checkPanelNumber(HttpServletRequest request, HttpServletResponse response, @RequestParam("panelNumber") String panelNumber, @RequestParam("execution") String execution) { ...... Gson gson = new Gson(); return new ResponseEntity<String>(gson.toJson(details), HttpStatus.OK); }

However it works perfectly fine for GET method! Tried adding dataType: "json" as well but with this even GET call stops working. Browser console shows error as HTTP 400 bad request but when checked through firefox plugins the POST parameters are going fine. Any help?

-------------Problems Reply------------

Spring is a little touchy when it comes to @RequestParam, POST body, and JSON content-type: it simply won't parse them. You can solve this problem one of three ways:

  1. Change the content-type to be application/x-www-form-urlencoded
  2. Change the two @RequestParam to be a single @RequestBody Map<String, Object> body, then use that Map to manually parse out your parameters.
  3. Set up a custom Argument Resolver that can parse JSON for your desired values.

The second method is likely the easiest to change, but it loses you some of the automagic validation that Spring does for you.

Category:javascript Views:2 Time:2017-09-10

Related post

  • JQuery AJAX post not working if more than 1 function is defined 2011-06-23

    I have a JQUERY AJAX post function that will work if there is one function, but if I try and include another function in addition, the second function does not post through to the .PHP script. I am a beginner in JQUERY but have tried every variation,

  • jQuery AJAX post not working, but works with curl 2009-08-24

    I'm trying to make a post request via ajax using jQuery (for the BaseCamp API), and I can't seem to get it to work. I can get it to work using curl just fine, so I know it's something I'm doing wrong with jQuery. Here's the curl command which works:

  • jQuery AJAX Post not working 2009-12-06

    I cant not figure out why this script doesnt work. It has to do with something within the AJAX POST script/function. Right now, when I hit submit on my form it runs the php code on the same page. What it should do it is send the values of the form to

  • jquery ajax post not working with .load in codeigniter 2010-12-22

    i wish to .load multiple views result with jquery ajax the original code (js) $(document).ready(function(){ $("#uid").change( function(){ var uid=$("#uid").val(); $.ajax({ type: "POST", url: "<?= site_url('sp_profile/ajax_userdetail') ?>", data

  • jQuery ajax post not calling method in my controller 2009-11-15

    I have a list of tasks that I allow a user to sort, currently I am working on the dragging/dropping from one container to the other. While the dragging/dropping works, I can't get the jQuery post to fire. Not sure what's going on here. Here is what I

  • trouble with jQuery ajax post not submitting data to asp page 2011-12-11

    I have a Greasemonkey script that submits a form via an ajax request (post) with all the required name/value pairs. I get a response to the request but it does not contain any response to the data posted to the page. For instance the server should re

  • jquery ajax post - not being fired first time 2011-03-04

    I'm trying to do an ajax post after a button is clicked, and it works in firefox but not in IE the first time the page is loaded. It does work if I refresh the page and try again second time - but not first time and this is crucial. I've scanned over

  • ASP.NET MVC 3 Jquery Ajax post not receiving response until server side async function is completed 2011-06-23

    I'm posting a form to an MVC action using jquery Ajax. Server side, I call a send mail async function. While debugging, I can see execution continue all the way through the return statement from the action. Even though the return statement is reached

  • Jquery ajax post not working on iPhone and Android 2011-04-07

    I'm building a web application targeting mobile devices (specifically iPhone and Android). I'm building it using ASP.NET MVC and JQuery. On one page I have a cascading dropdown. I've hooked up a function on the change event for the first dropdown and

  • jquery ajax post - not working first time page loads 2011-02-09

    I have some ajax/jquery code in one of my pages and the problem I'm having is that it doesn't work the first time the page is loaded. If I refresh the page it works no prob. It does work in firefox first time. All the variables that I'm using are ok

  • jQuery Ajax POST not working with MailChimp 2011-03-04

    I have the following code I am using to send data to a MailChimp Newsletter List (API v3). Everytime I remove the type: POST from the function it attempts to post the data via GET and it sends the data properly (ok response in MailChimp API dashboard

  • JQuery AJAX Post Not work on FF , Safari 2014-12-23

    I have this code but is not working on FireFox and Safari Browser. But works fine and IE and Chrome. Any ideas ? function formData() { var serializedValues = $("#msform").serialize(); var form_data = {action: 'ajax_data', type: 'post', data: serializ

  • Downloading Via JQuery AJAX Post not working 2011-12-02

    i want to download a file using ajax via post request using jQuery. here is the PHP code i am using. if (file_exists($file)) { header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; fil

  • jQuery AJAX Post doesn't work 2012-04-05

    I can't figure out why the following code doesn't work. For the time being, the php function "alias_valid" just returns a string for testing purposes, so I haven't included the php function here. The alert is empty. $.post(SITE_ROOT + "includes/Abstr

  • jQuery Ajax post not passing parameters 2011-02-20

    I'm attempting to use jQuery's $.ajax() function to post form variables to an MVC route. Problem is, when the code hits my MVC action, all of the parameters are null, even though data is being passed to them: jQuery: $(function () { $('#signupform').

  • jQuery AJAX Post not posting data 2011-12-15

    Right I have given in, after about 2 hours trying to figure out this issue I've caved, help me out stackoverflow! Trying to post a product id along with quantity to a php file that will return errors if it finds any jQuery code - $('span.add_to_cart'

  • ajax jquery php: w3school example jquery ajax post not displaying suggestion 2012-03-27

    I tried the following code from w3schools. When I enter letters in a input txt box, suggestions should get displayed accordingly. However, nothing is getting displayed as suggestion. I'm not able to get the txt value with serialize. In gethint.php, s

  • JQuery AJAX post to asp.net webmethod never getting called 2010-08-20

    I have a web method in one of my aspx pages: [WebMethod] public static string AddDebt(int userId, int type, string description, float amount) And in the aspx page I have the JQuery $(".addDebt").click(function (e) { e.preventDefault(); var userId = $

  • jquery ajax post works fine in IE, FF, Chrome but not Safari 2011-10-13

    I am posting a form to a remote server via the action method, but calling a jquery function to updata a database prior to the post - all works fine in IE, FF etc. ... but, Safari always fails to do the jquery database insert when return is true OR as

  • jQuery ajax call not working in FF and safari works in IE 2010-03-08

    I made a little module to use a jquery/ajax script on my website. For that I used examples which are on the site and others. The script is working in IE (for a change it works there) but I cannot get it working in FF or safari. Tried a lot of things

  • Trouble getting unobtrusive validation working with mvc 3 on jquery ajax post 2011-08-10

    I have having a lot of trouble getting validation to work on MVC3. It works fine when I just load the page directly, but it does not validate when I use jquery AJAX POST: This form is loaded using $('#modal-dialog').load('/DartsMVC/Restaurant/Edit/13

  • jQuery Ajax call not working in Chrome Browser 2011-01-04

    jQuery Ajax call not working in Chrome Browser. my code :- function memories(pageName) { $.ajax({ type: "POST", url: pageName, success: function(html){ $("#page").load(pageName); } }); } --------------Solutions------------- You're calling load, but n

  • jQuery $.ajax does not work 2011-09-07

    I wrote a code using jQuery plugin fullcalendar, and everything worked just fine, until I send an $.ajax request in the eventClick. I tried to alert something in the eventClick and it worked, but the ajax request just doesn't work. js code: !function

  • Internet Explorer not rendering html returned from JQuery ajax post 2009-12-03

    I have a page with an input box whose onkeyup fires a JQuery ajax post based on what was typed (a search field) The ajax call's posted back html is supposed to populate another div on the page. Here is the jquery ajax post: var o = $(me.results).empt

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.173 (s). 11 q(s)