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
Javascript: How to Validate Dates in Format Mm-Dd-Yyyy
Write/Add Data in JSON File Using Node.Js
How to Force Angular2 to Post Using X-Www-Form-Urlencoded
Array.Push() If Does Not Exist
How to Append a Div Inside an Svg Element
How to Bind the HTML <Title> Content in Vuejs
Where Should I Declare JavaScript Files Used in My Page? in <Head></Head> or Near </Body>
How to Play HTML5 Video in Reverse
Save File JavaScript with File Name
Should I Use Encodeuri or Encodeuricomponent for Encoding Urls
What Advantages Does Using (Function(Window, Document, Undefined) { ... })(Window, Document) Confer
Javascript/Jquery: Test If Window Has Focus
Should an Async API Ever Throw Synchronously
Jquery Post() with Serialize and Extra Data