Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 924
  • Last Modified:

Need a 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.
$.getJSON('../advice/php/get_advice_start.php', {ID : top.window.location.hash.substring(1)}, process_advice);
                        function process_advice(data) {
advice_ID = data.id;
}
 
$('#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

0
Sucao
Asked:
Sucao
1 Solution
 
alien109Commented:
the result of a the serialize method is a string. To add your ID parameter, you'd need to do this:

$.post('../advice/php/post_comment.php', form_data + "&ID=" + advice_ID, comment_callback);
0
 
SucaoAuthor Commented:
thanks alien109 that did the trick
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now