Home › Forums › JavaScript › Need Help Getting PHP/MySQL form processed via AJAX
- This topic is empty.
-
AuthorPosts
-
May 8, 2011 at 9:42 am #32611EamonnMember
Hi Guys,
The following code pieces are:- My opening Javascript snippet, forming the obj, in the header
- The form, a dropdown, populated via PHP
- The processing script, on tester-engine.php
I am completely new to AJAX, and cannot see where this is falling down. Any help and explanations would be hugely appreciated.
The header script:
The Form:
// db connection established
Person info will be listed here.
And, finally, the proccessing script:
$q=$_GET["q"];
// connection esablished
$sql="SELECT * FROM contacts WHERE id = '".$q."'";
$result = mysql_query($sql);
echo "
";
";
Firstname
Lastname
while($row = mysql_fetch_array($result))
{
echo ""; ";
echo "" . $row . " ";
echo "" . $row . " ";
echo "
}
echo "
Thanks in advance!
May 8, 2011 at 1:17 pm #77168ChrisBullMemberWhat’s wrong with it, Is is the request getting sent, is php not sending anything back, is the javascript function even getting called…?
May 8, 2011 at 4:36 pm #77164EamonnMemberWell, it actually worked fine when the form options were hard coded as opposed to being auto populated via php. Now it doesn’t, and I just can’t figure why. I don’t know enough about AJAX to know if there’s an issue with php defined variables, and every example I can google seems to have hard coded values.
To be clear – the form is being populated fine, but now, on selection, no response is being shown.
May 9, 2011 at 7:13 pm #76955EamonnMemberBump in hope….
May 12, 2011 at 9:39 pm #76403smithbhMemberThis isn’t a solution, but may point you in the right direction.
If you’re passing your values into a PHP array named “q” using GET, I’d recommend using the jQuery 1.5.0 .serialize() function to grab all the parameters from your form and passing them via the AJAX-inherent .get() function.
Example:
1) Add the following to your Header:
2) Assign an ID to your form(this is my own personal preference as I favor using the jQuery ID selector):
3) Not sure what event you’re using to submit the form – if using a submit button, add the following:
Like I said, this isn’t a solution, but should help point you in the right direction. Also, I typically prefer to use the POST method as opposed to GET. To use this method instead, simply replace the above jQuery $.get(); function with $.post(); and replace $q=$_GET[“q”]; with $q=$_POST[“q”]; in your PHP.
Hope this helps!
Brandon
http://www.vconstruct.com
Build On The Cloud -
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.