Solved

Need a way to send multiple data for $.post()

Posted on 2009-05-18
2
894 Views
Last Modified: 2012-08-13
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
Comment
Question by:Sucao
2 Comments
 
LVL 12

Accepted Solution

by:
alien109 earned 500 total points
ID: 24414998
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
 

Author Comment

by:Sucao
ID: 24415098
thanks alien109 that did the trick
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now