4

How can I add parameters to a post request using .post or .ajax. I tried:

var formData = $('form').serialize();
$.ajax({
url: "url",
data: formData,
type: "POST",
dataType: "dataType"
});

but that doesn't seem to work.

2
  • Have you looked at this, previous, answer on SO? stackoverflow.com/questions/370359/… Commented Jun 7, 2012 at 13:47
  • Yes I did, I was a little bit frustrated. I tried this alot.. I dont get why when I do the following, code$(document).ready(function() { $('searchsubmit').click(function() { var formData = $('form').param(); $.ajax({ url: 'Search', type: "POST", data: formData, succes: function(data) { alert(data); } }); alert("blabla"); }); alert("blabla"); });code My servlet does nothing. Commented Jun 7, 2012 at 14:09

5 Answers 5

3

Just add it to your formData before send?

var formData = $('form').serialize();
$.ajax({
    url: "url",
    data: formData + '&param=' + param_value,
    type: "POST",
    dataType: "dataTpe"
});
Sign up to request clarification or add additional context in comments.

Comments

1
$.ajax({
    url: "url",
    type: "POST",
    //dataType: 'json',
    data: formData,   
    success: function(data){

    }
});

Comments

0

Use .param, not .serialize. The former returns an object, the latter returns a string.

http://api.jquery.com/jQuery.param/

Comments

0
data: $('#myForm').serialize() + "&moredata=" + morevalue

Comments

0

following acrashik's answer the following code works:

     var aData = table.fnGetData( this,0 );
     $.ajax({
         url: "MessageDetail",
         type: "POST",
         data: "messageid=" + aData,
         succes: function(data) {
            alert(data);
        }
     });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.