Link to home
Start Free TrialLog in
Avatar of Sucao
Sucao

asked on

Correct way to send multiple data for $.post()

I need to send some data to a php script. Some of the data is coming from a textarea and some of it is coming from a variable (advice_ID) defined earlier in the javascript. Below is the code that I am using trying to send the data.

when I leave out the "+ {ID : advice_ID}" the code inputs form_data fine but I need to send that advice_ID.

when I leave in "+ {ID : advice_ID}" the code adds "[object Object]" to the end of the form_data.

don't know if that helps you diagnose the problem.
$('#comment_form').submit(function() {
var form_data = $(this).serialize();
			$.post('../advice/php/post_comment.php', form_data + {ID : advice_ID}, comment_callback);
							function comment_callback(data) {
					}
			return false;
								   
});

Open in new window

Avatar of alien109
alien109
Flag of United States of America image

Hard to know for sure, without seeing what advice_ID is getting set to and how, but I'm guessing that advice_ID is not a string. Can you show how/where that variable is getting set?
Avatar of Sucao
Sucao

ASKER

Yea sure alien109. It's getting set earlier from a $.getJSON().

also, usually it gets set as something like '47' or some other number. not sure if that counts as being set as a string or just as a number.

sorry for my newbie ways on this one.
$.getJSON('../advice/php/get_advice_start.php', {ID : top.window.location.hash.substring(1)}, process_advice);
			function process_advice(data) {
advice_ID = data.id;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sucao
Sucao

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial