Alex Rivera | Logout

JQuery - $.ajax POST does not send .data to web server

Asked 2011-04-08T14:11:47.370
9

I am using the JQuery $.ajax post command to invoke an ajax event on my web server:

var formParams = "fe1=y&fe2=m&fe3=m";

$.ajax({
    type: 'POST',
    url: '/foo.jsp',
    async: false,
    data: formParams,
    complete: function(xmlRequestObject, successString){
        ymmReceiveAjaxResponse(xmlRequestObject, successString);
    }
});

The ajax component successfully calls the web page, but it does not include any of the post data.
ie - "(HttpServletRequest) request.getParameterMap.size() == 0" - I'd expect 3, but am getting zero.

Changing the above command from POST to a GET makes everything work just fine.

TIA

Edit
Report

2 Answers

1

Try this :

$.ajax({
    type: 'POST',
    url: '/foo.jsp',
    async: false,
    data: { fe1: "y", fe2: "m", fe3: "m" },
    complete: function(xmlRequestObject, successString){
        ymmReceiveAjaxResponse(xmlRequestObject, successString);
    }
});

It should work.

answered 2011-04-08T14:17:29.840
-1

Use success:

var formParams = "fe1=y&fe2=m&fe3=m";

$.ajax({
    type: 'POST',
    url: '/foo.jsp',
    async: false,
    data: formParams,
    success: function(data) {
       alert('response data = ' + data);
    }
});
answered 2011-04-08T14:17:16.083

Your Answer