Run several queries to update the current page. Looking for hints or options

I have created 3 API queries. It starts with an autocomplete form that returns a street address and zip code. The second gets the 9 digit zipcode from USPS and the third gets the local sales tax based on the 9 digit zip, from the state. All three queries work as needed. The zip query is a php script that just returns the zip and the third is a php script that just returns the tax rate. I would like to get the second and third queries to run in sequence, and then update the current page without the user needing to do anything. Can anyone suggest my options for doing this.

What I have done so far is to use basically a next, next using session variables to pass updated information to the next page. The new page is an identical page to the first with the updated information. So I have page1.php → page2.php → page3.php. What I would like to know is, can this be done without user intervention such that the information is updated into page1.php and assuming so, what might my options be.

   <?php
session_start();
$_SESSION['street_number'] = $_POST['street_number'];
$_SESSION['route'] = $_POST['route'];
$_SESSION['city'] = $_POST['city'];
$_SESSION['state'] = $_POST['state'];
$_SESSION['zip'] = $_POST['zip'];
$_SESSION['name'] = $_POST['name'];
$_SESSION['phone'] = $_POST['phone'];
$_SESSION['address'] = $_POST['street_number']." ". $_POST['route'];
?>


<?php
$street = $_SESSION['address'];
$zip = $_SESSION['zip'];
$city = $_SESSION['city'];
$state = $_SESSION['state'];
 
$input_xml = <<<EOXML
<AddressValidateRequest USERID="XXXXXXXXX">
    <Address ID="0">
        <Address1></Address1>
        <Address2>$street</Address2>
        <City>$city</City>
        <State>$state</State>
        <Zip5>$zip</Zip5>
        <Zip4></Zip4>
    </Address>
</AddressValidateRequest>
EOXML;

$fields = array(
    'API' => 'Verify',
    'XML' => $input_xml

Could you use Ajax to make these calls in the background while your user is filling the form in? So as soon as the user has provided enough information to call the second and third PHP scripts, call them in the background and stick the results back into your form.

It might be better to look around the Javascript section of the forum for more information, as the bulk of the interaction will be done in JS.

I am new to this. Should I delete this post and ask it again in the Javascript section?

No, just have a look around that section and see if any of the Alax-related stuff goes towards answering your question. I haven’t been in the JS section for a while but I’m sure there were lots of similar things for those starting out with Ajax. I certainly found a few when I was trying to figure it out. You might find a few in here, as there’s quite a lot of overlap.

I could move your post, if you like, but once you are looking for Ajax I think you’ll find enough examples to get you moving.

I am very inexperienced in programming. A smattering of php over the years and zero JS or Ajax. I basically guess at what I need and search for code examples and read and search and read. I eventually come up with things like I posted. Probably not good code or even the most appropriate but they work. I won’t have a real clue about how to really ask or know what I am looking for.

Have a read up on starting Ajax - it’s really quite simple to start with, and then you can build on that.

Thanks. I have been looking and it does look doable for me.