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.
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;
});
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?
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.
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;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.