We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,605 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

MySQL query from HTML Form - Handing JSON response

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?

2
Contributors
1
Reply
1 Day
Discussion Span
3 Months Ago
Last Updated
12
Views
ChrisXL
Newbie Poster
4 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

pritaeas
Posting Prodigy
Moderator
9,542 posts since Jul 2006
Reputation Points: 1,194
Solved Threads: 1,494
Skill Endorsements: 98

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0692 seconds using 2.67MB