Welcome Guest, Not a member yet? Register   Sign In
How to Joining 2 variables in jQuery ?
#1

[eluser]dimasVS[/eluser]
Hi all, I get a problem..
I wanna ask, how to join 2 variables in jQuery when I wanna post this to my controller ?

For Example :

[removed]
function test(){
var data_all = $('form#mst_form').serializeArray();
var user_id = $('#user_id').val();

$.ajax({
type: 'POST',
url: '<?php site_url(); ?>test/insert',
cache: false,
data: data_all + user_id, //How to join data_all and user_id ? cause I get error message
success: function(msg){
alert('success');
}
});
}
[removed]

Thank You...
#2

[eluser]Dalen[/eluser]
if data_all contains elements of the same type of user_id then

Code:
data_all.push(user_id);
#3

[eluser]dimasVS[/eluser]
It doesn't work,
get error message too..

Is there any other solution ?
#4

[eluser]Dalen[/eluser]
you can't send a javascript array that way in ajax!
Code:
var tobesent = JSON.stringify(data_all.push(user_id));
#5

[eluser]dimasVS[/eluser]
thanks Dalen,
It works..

var tobesent = (data_all.push({name: "user_id", value: user_id}));




Theme © iAndrew 2016 - Forum software by © MyBB