Jump to content

Adding data to an object (jQuery/ajax)


Go to solution Solved by trq,

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.