Jump to content

Adding data to an object (jQuery/ajax)


GuitarGod

Recommended Posts

Hi all,

 

I'm using jQuerys ajax function to send some data, however I would like to add a function to it that would gather up more data to be sent. Here's what I'm trying to do:

$.ajax({
type : 'POST',
url : 'ajax.php',
data :
{
  action : 'customer_details',
  more_customer_details( 'complaint' )
},
success : function( msg )
{
//
}
});
 
function more_customer_details( section )
{
  var cus = { details_sent : '1' };

  if ( section == 'complaint' )
  {
  cus['name'] = $( '#'+section+'_name' ).val();
  cus['msg'] = $( '#'+section+'_msg' ).val();
  }
  else if ( section == 'support' )
  {
  cus['id'] = $( '#'+section+'_id' ).val();
  }
  return cus;
}

As you can see, the reason I'm wanting to use a function to gather extra details is because the object parameters and values will be changed based upon a selected action, however this doesn't seem to work. Is there any way to return an object and it to jQuery ajax data section?

 

Thanks for any and all help :happy-04:

Link to comment
https://forums.phpfreaks.com/topic/281493-adding-data-to-an-object-jqueryajax/
Share on other sites

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.