I need to send to server form data and some array. I'm trying to do next:
var array= [3,4,5,1,2]
var form = $(this);
var url = $(this).attr("action");
And $.post(url, {form: form, array:array})
But it's not sending.
Or you can do this:
var array= [3,4,5,1,2];
data={
form:$(this).serialize(),
array:array
};
$.ajax({
url:$(this).attr("action");
type:'POST',
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: data,
success:function(data){
//Success process
},
error:function(data){
//Error process
},
});
you can send form data by using serialize method
try this-
var array= [3,4,5,1,2]
var form = $(this).serialize();
var url = $(this).attr("action");
$.post(url, {form: form, array:array},function(result){
$("span").html(result);
});
data in ajax post is send like this-
{ key1 : value1 , key2 : value2 }