Jquery Post() with Serialize and Extra Data

How to add data via $.ajax ( serialize() + extra data ) like this

What kind of data?

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

The "data" parameter is just a URL encoded string. You can append to it however you like. See the API here.

jQuery post() with serialize and extra data

You can use serializeArray [docs] and add the additional data:

var data = $('#myForm').serializeArray();
data.push({name: 'wordlist', value: wordlist});

$.post("page.php", data);

add additional data to $form.serialize() ajax post?

try this:

$.ajax({ 
type: 'post',
url: '/process/somepage.php',
data: $form.serialize() + '&hours=' + JSON.stringify(selectedHours),
dataType : 'json'
}).done(function (response) {
... and so on...

data sended are just a URL encoded string. You can append other value with a simple concatenation.

send a form with serialize() function and extra data in ajax()

The serialize function simply creates an URL query string from all the form elements. So you can manually add the variable to the result of the serialize() function like this:

 data: $("#period-form").serialize() + '&idCompany=' + idCompany

how to pass a additional data with form serialized data on ajax?

From jQuery API DOCS

The .serializeArray() method creates a JavaScript array of objects

The .serialize() method creates a text string in standard URL-encoded notation.

I think to use push , we need to use serializeArray

try to use

var frmData = frm.serializeArray();
frmData.push({name: "name", value: "test"});

$(document).ready(function()
{
var additional_data=$("#extra_data").val();
$.ajax({
type: 'POST',
url: 'send_mail.php',
data: frmData,
success: function (data) {
alert(data);
}
});
});

jQuery: serialize() form and other parameters

serialize() effectively turns the form values into a valid querystring, as such you can simply append to the string:

$.ajax({
type : 'POST',
url : 'url',
data : $('#form').serialize() + "&par1=1&par2=2&par3=232"
}

$(this).serialize() -- How to add a value?

Instead of

 data: $(this).serialize() + '&=NonFormValue' + NonFormValue,

you probably want

 data: $(this).serialize() + '&NonFormValue=' + NonFormValue,

You should be careful to URL-encode the value of NonFormValue if it might contain any special characters.

how to add additional variable to serialized form for POST

Serialize builds a url-string of key-value arguments.

https://api.jquery.com/serialize/
like: single=Single&multiple=Multiple&multiple=Multiple3&check=check2&radio=radio1

I would advise you to add your token (which should be no array or object) as key value to it

data: $( "#profileForm" ).serialize() + "&token="+ token

How to add and retrive additional data to serialize() in jquery ajax?

Use .serializeArray()

var dataString = $("#myform").serializeArray();
dataString.push({
name: "type",
value: "myvalue"
});

What is the best way to add extra data to a jquery ajax post (in addition to a serialized form)?

Try using serializeArray

var data = $('#myFormName').serializeArray();
data.push({name: 'myParamName', value: 'MyParamValue'});

Update1:

You can use following code in $.post:

$.post('/Calendar/Add', data, function (data)    
{});

For more information have look at this.



Related Topics



Leave a reply



Submit