0

At first I was sending data over as one singular object like so:

function ajaxCall(){
    $.ajax({

                url: "someURL",
                data: data,
                type: "POST",
                dataType: "json",
                //more ajax stuff
});

$(document).ready(function() {
    $("#htmlForm").on('submit',function(e){
        e.preventDefault();
        data = $("#htmlForm").serialize();
        ajaxCall();
    });
});

And on the java back end I would receive my request parameters individually like so:

firstRequestParam,
secondRequestParam,
etc..

However, there is a new addition which looks like this:

function ajaxCall(jsonStuff){
    $.ajax({

                url: "someURL",
                data: {data: data, jsonStuff: jsonStuff}, 
                type: "POST",
                dataType: "json",
                //more ajax stuff
});

Now on the back end I get this:

firstRequestParam = data,
secondRequestParam = jsonStuff

What is the best way to get my individual request parameters back now that they are jumbled up and stored as the first property in the javascript object?

EDIT: This is not a duplicate. I understand how ajax works. I am able to send the data over properly in the javascript object. I am having trouble extracting the data on the java side since the data is now all wrapped up into one single request parameter instead of split up into multiple request paramaters. Previously if I had 3 fields text fields in the HTML form, if I did request.getParameter(paramName); they would come in as: field1, field2, field3. Now, if I do the same request.getParameter(paramName); I get: data, jsonStuff.

REAL O G
  • 693
  • 7
  • 23
  • `data` and `jsonStuff` contain what your javascript sent. What exactly are you having a problem with? – mariocatch Aug 05 '16 at 02:40
  • What u mean by Java ?Servlet in Jee , Controller of Spring MVC , Controllerof JSF ???? – Abdennour TOUMI Aug 05 '16 at 02:40
  • this is how ajax works, what is your problem again? I didn't get it – Anonymous Duck Aug 05 '16 at 02:41
  • Possible duplicate of [How to send data to servlet using ajax without a submitting form](http://stackoverflow.com/questions/31168646/how-to-send-data-to-servlet-using-ajax-without-a-submitting-form) – Abdennour TOUMI Aug 05 '16 at 02:44
  • @AbdennourTOUMI It is a Java Servlet in JEE. At first I was extracting the request params simply by doing `request.getParameter(paramName)` using if else statements, which worked before since ajax sent over the `data` from the HTML form individually for each field. Now, each field is not sent over individually, but is wrapped up all in one into the `data` property of of the javascript object. – REAL O G Aug 05 '16 at 02:45
  • Both examples are being POST'd – Scary Wombat Aug 05 '16 at 02:46
  • what specifically does "data" and "jsonStuff" look like? the "data" arg of ajax() should be serialized per the rules outlined in jquery.param (http://api.jquery.com/jQuery.param/) - are you not seeing these keys in HttpServletRequest? are you _actually_ seeing httpServletRequest.getParameter("firstRequestParameter") return a non-null value? – jamey graham Aug 05 '16 at 03:17

0 Answers0