dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Posting query results

  1. #1
    Join Date
    Aug 2007
    Posts
    10

    Posting query results

    Hi Folks,

    As of yesterday I was brand new to AJAX and need some assistance.

    I have an SQL query and I want to post its results to an HTML form. Problem is is it's dynamically generated so a simple inner text option is not so simple.

    An example:

    Query grabs store data from the database (StoreID, StoreName, StoreLocation). Let's say I just want to post the store name to a form. For the time being I have global variables to test this so is there a way to get StoreName from the database to one of these global variables.

    Thanks!

  2. #2
    Join Date
    Jul 2007
    Posts
    4
    Would you like to look over this intro:

    http://www-128.ibm.com/developerwork...Mastering+Ajax

    Andy

  3. #3
    Join Date
    Aug 2007
    Posts
    10
    Hi Andy,

    I reviewed a couple tutorials and I've conjured the following:

    var ajaxRequest;

    try
    {
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
    }
    catch (e)
    {
    // Internet Explorer Browsers
    try
    {
    ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
    try
    {
    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e)
    {
    // Something went wrong
    alert("Please use a Firefox, Opera or Netscape.");
    return false;
    }
    }
    }

    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
    document.myForm.time.value = ajaxRequest.responseText;
    }
    }


    var queryString = "?StoreNo=" + storeNoTxt.value + "&OwnerName=" +
    ownerNameTxt.value + "&CoordinatorName=" + coordinatorNameTxt.value;
    ajaxRequest.open("POST", "dataSubmit.php" + queryString, true);
    ajaxRequest.send(null);

    The PHP script it's accessing is in the same folder as this script and it looks like this:

    <?php

    $storeNo = $_GET['StoreNo'];
    $ownerName = $_GET['OwnerName'];
    $coordinatorName = $_GET['CoordinatorName'];

    echo "Database stuff";
    echo $storeNo . ", " . $ownerName . ", " . $coordinatorName;

    ?>

    As you can see I'm just trying to output the data to verify it's even getting passed.

    At first blush I thought there was something wrong with my URL but I confirmed that /.../dataSubmit.php, while accessible from my browser is not with this script. I also tried simple redirection using the web page the JavaScript resides on and all I needed was dataSubmit.php.

    If you have any ideas I'm all eyes.

    Thanks!

    PS - I'm using Mozilla Firefox if that makes a difference.

  4. #4
    Join Date
    Jul 2007
    Posts
    4
    Hi Canadiancoder,

    http://www.tizag.com/ajaxTutorial/aj...l-database.php

    This site has a cut & paste example to get you started.

    Firefox Firebug is the best friend I have for ajax debugging.

    This isn't rocket science but the syntax is unforgiving. I believe it is appropriate to get an understanding of the process in order to set up your scripts.

    Either of the two links you now have are good. Also, the w3schools has a nice tutorial.

    Andy

  5. #5
    Join Date
    Aug 2007
    Posts
    10
    Hi Andy,

    Thanks for the tips. The Firebug mod served me beautifully so to anyone else reading this I strongly recommend downloading it. It'll save your sanity!

Similar Threads

  1. Replies: 1
    Last Post: 06-26-2002, 03:29 AM
  2. Outputting results of query as xml
    By Tom in forum Database
    Replies: 0
    Last Post: 03-26-2002, 12:21 PM
  3. Using For XML Auto query results
    By Marco in forum Database
    Replies: 0
    Last Post: 06-14-2001, 01:01 AM
  4. Save results of query
    By Paul in forum Database
    Replies: 2
    Last Post: 11-28-2000, 08:35 PM
  5. How to deal with no results from query
    By Shawn Call in forum Web
    Replies: 1
    Last Post: 05-03-2000, 04:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center