Jump to content

Sending dynamic content with jQuery


GuitarGod

Recommended Posts

Hi all,

 

I'm currently using jQuery's load function to send/load data into a page element, but I'm having trouble figuring out how to send dynamic data.

var option_count = $( '#opt_count' ).val(); // This number is subject to change on every page
var opts = '';
 
for ( i = 0; i < option_count; i++ )
{
  opts = opts+'&option_'+i+'='+$( '#option_'+i ).val();
}
 
// So the data above could be &option_0=7&option_1=4&option_2=9 etc
// but I can't seem to send option as an individual parameter
 
// I've tried
 
$( '#contain' ).load(
'receiver.php',
{
page_no : "2"+opts,
});
 
// I've also tried
 
 
$( '#contain' ).load(
'receiver.php',
{
page_no : "2",
opts
});
 
// What I'm trying to convey is
 
$( '#contain' ).load(
'receiver.php',
{
page_no : "2",
option_0 : 7,
option_1 : 4
// etc etc..
});

However, the number of options and their values are dynamic and subject to change. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/281241-sending-dynamic-content-with-jquery/
Share on other sites

var option_count = $( '#opt_count' ).val(); // This number is subject to change on every page
var opts = {page_no:2};
for ( i = 0; i < option_count; i++ )
{
  opts['option_'+i] = $('#option_'+i).val();
}

$( '#contain' ).load('receiver.php', opts);
 

Create the opts object with the page_no option to start, then add each option_x property in the loop.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.