Solved

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

Posted on 2009-05-18
2
901 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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…

920 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

11 Experts available now in Live!

Get 1:1 Help Now