GuitarGod Posted August 23, 2013 Share Posted August 23, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/281493-adding-data-to-an-object-jqueryajax/ Share on other sites More sharing options...
Solution trq Posted August 23, 2013 Solution Share Posted August 23, 2013 data : { action : 'customer_details', more_customer_details: more_customer_details( 'complaint' ) } Quote Link to comment https://forums.phpfreaks.com/topic/281493-adding-data-to-an-object-jqueryajax/#findComment-1446457 Share on other sites More sharing options...
GuitarGod Posted August 23, 2013 Author Share Posted August 23, 2013 Absolutely brilliant. Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/281493-adding-data-to-an-object-jqueryajax/#findComment-1446479 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.