Solved

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

Posted on 2009-05-16
3
642 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:Sucao
  • 2
3 Comments
 
LVL 12

Expert Comment

by:alien109
ID: 24406357
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?
0
 

Author Comment

by:Sucao
ID: 24406593
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

0
 

Accepted Solution

by:
Sucao earned 0 total points
ID: 24415122
This is what Alien109 posted in a different post based on the same question.


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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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 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)

758 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

20 Experts available now in Live!

Get 1:1 Help Now