Page 1 of 1

passing 2 variables from jquery to php file

Posted: Fri Jun 03, 2011 9:16 am
by bluestar
i have syntax problem while transferring more than 2 values from jquery to php file ..but code dint work...when i try to transfer only 1 variable it works but
not with more than 1 variable....here is the codes that im using..

var data1=$("#textbox1").val(); //textbox with name textbox1 in html page
var data2=$("#textbox1").val(); //textbox with name textbox2 in html page
$.ajax({
type: "POST",
url: "insert.php",
data: { data1,data2}, //i stuck in this line
cache: false,
success: function(html){
//some codes here
},
});

in insert.php file:

if(isset($_POST['data1'])||isset($_POST['data2']))
{
echo $_POST['data1'];
echo $_POST['data2'];
}

Re: passing 2 variables from jquery to php file

Posted: Fri Jun 03, 2011 10:26 am
by pickle
You're not setting the names of those variables. You need to do something like:

Code: Select all

{nameOfVariable:data1,nameOfSecondVariable:data2}

Re: passing 2 variables from jquery to php file

Posted: Sat Jun 04, 2011 7:45 am
by bluestar
dint worked....i also tried
1)var datasent = 'contet='+ test+'&txt1='+test2;
data : datasent,
2)var datasent = 'contet:'+ test+'&txt1:'+test2;
data : datasent,
3)data:{ contet : $("#textbox1").val() , txt1=$("#textbox1").val()}, /