Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6768815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:07:09+00:00 2026-05-26T15:07:09+00:00

How can I pass the values of a jQuery callback function to a PHP

  • 0

How can I pass the values of a jQuery callback function to a PHP script for further validation? Here, I recieve a latitude and longitude from a getJSON function. I need to use these values to hit the DB wherein they will be compared against existing coordinates to find nearby locations; i.e. a proximity search.

$('#form_map').submit(function() {      

    var pc = $('#post_code').val();
            if(pc != '') {
                $.getJSON('/mod/gg.php?pc='+pc, function(data) {
                    lat = data.results[0].geometry.location.lat;
                    lng = data.results[0].geometry.location.lng;
                    });
                }
            return false;

            });

I want to take the values of lat / lng and turn them into php variables. It’s a proximity search. First the user inputed address is turned into coordinates, then it hits the DB through a PHP script. I need the coordinates that were returned from the JSON array to be usable as PHP variables so they can hit the DB.

<?php 
if(isset($lat) && isset($lng)){
// Do something
}

Upon receiving the lat / lng values, I want them to be <php $lat = 'Value of callback funcion'; $lng = 'Same'; ?> Then I can run down the rest of the PHP script. How can I do this? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:07:09+00:00Added an answer on May 26, 2026 at 3:07 pm

    First of all: why not store the values in the DB before replying to the ajax request?

    If you actually want to do that with a “callback”, you can use a second ajax as the callback to execute your persistancy script.

    $.getJSON('/mod/gg.php?pc='+pc, function(data) {
                        lat = data.results[0].geometry.location.lat;
                        lng = data.results[0].geometry.location.lng;
                  $.post("/mod/storeindb.php", { lat : lat, lng : lng }, function(data){
                         // do something with whatever you return
                  });
         });
    }
    

    You must pay attention: php is executed in server-side, javascript is executed client-side. They are both autonomous and the only thing bridging them are HTTP request. And these run asynch. Which means that what you are calling a “callback” will be actually another ajax call to a different script.

    I’m just saying this because I got the feeling that you wanted a blocking callback to have linear execution within the same script (and that is not possible). If not ignore this last paragraph

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I pass form values in load() function of jQuery then be able to
I need to pass an array of numeric values from jQuery to a php
how can i pass values from my custom components back to the main.mxml? i
I need to pass extra variables to a jQuery, ajax callback function. For example,
I am creating a function that I need to pass in values from an
How can I pass more than one parameter from jQuery to an ASHX file.
I can't seem to understand why I cant pass any values with the following
Can I pass a value out of a javascript function and back to the
How can I pass a variable value from a template using JavaScript without using
How can I pass the result from a scalar [single row, single value] query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.