Rodolfo
Rodolfo

Reputation: 105

How to pass an uncertain number of php variables through JQUERY / AJAX

Please, look at this PHP script (sendingpage.php):

$i=1;

While(whatever){

echo "<input id='ref".$i."' type='hidden' value='".$variable."' />";
echo "<input id='ref2".$i."' type='hidden' value='".$variable2."' />";
$i++;

}

Now, what I want to do is passing all values to another php page (receivingpage.php) using the JQUERY AJAX method and after processing the received data in receivingpage.php loading the result in my sendingpage.php. Note that I do not know how many cicles this script will generate nor what values $variable and $variable2 will hold at each cicle.

I think I can go through all the final loading thing, but where I'm having troubles is at passing all values from sending.php to receiving.php using AJAX/JQUERY

I hope any of you throw some light on it for me. I would be really grateful.

Upvotes: 2

Views: 193

Answers (1)

techie_28
techie_28

Reputation: 2133

If this is inside a <form> then you can use serialize function to pass it as a data in ajax call. like

$.ajax({
     type :'POST',
     data:$('#formId').serialize();
     ...so on
}) 

It is also recomended to set type to post as it will allow you to send it as post request and will send all form fields in the request.

Upvotes: 2

Related Questions