1,105,644 Community Members

MySQL query from HTML Form - Handing JSON response

Member Avatar
ChrisXL
Newbie Poster
4 posts since Dec 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hey everyone. Got a problem that I really need help solving.

I have a page where a user is able to search a database for certain criteria (species/location/dates etc). What I have so far is when the form is submitted, the values are posted to a PHP script, which performs a MySQL query and then returns the result in json_encode(). What I want to happen is:
- User fills form
- User clicks submit
- Input values held in JavaScript
- JavaScript calls the PHP script that peforms the query and returns result as JSON
- JavaScript gets JSON response, and iterates through placing markers on a Google Map.

Now I have all the key features here, but combining them together is causing me a headache, and I know that AJAX is my solution. Here's my HTML that calls the JS.

<form id="form" name="form" method="post" onclick="getQuery()">

The JS getQuery():

function getQuery(){
    $.ajax({  
        type: "GET", 
        url: 'userquery.php', 
        data: "",  
        complete: function(data){ 
            var test = jQuery.parseJSON(data);
            alert(test.names[0]);
            alert("here");
        }
    },
        "json");
}
getList();

Obviously this needs work in order to produce the results I desire, but at the moment I'm just trying have the response available for handling.

Any help pleeease?

Member Avatar
pritaeas
mod_pritaeas
11,335 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 

I know there is a post/code snippet about this, but I cannot find it.

Anyway, you need to serialize your form, and pass it as data to your PHP script.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article