Solved

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

Posted on 2009-05-16
3
648 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to init a part of Javascript based on PHP value for Datatables & Yadcf 8 60
javascript: add id amounts 5 57
Passport Expiry 3 58
Generate Numbers in JQuery file 11 66
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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…

789 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