1

There are 3 files involved here: coordinates_update.html, passitalong.js, and dbquery.php

Coordinates update includes jquery,javascript, and passitalong.js, when a button is pressed it gets a bunch of variables and calls function in passitalong.js while passing the variables to this function. I have confirmed this works via an alert statement. Pass it along.js now includes a line of ajax code to pass those variables to qbquery.php(meant eventually to query the database but for now it's just for testing). dbquery.php then uses a get statement to get the variables and it should echo it.

The problem is when it passes the variables to the PHP file nothing happens afterward. It dosen't echo any of the variables back or a test echo I put in it, and opening it does nothing. Here is the relevant code:

coordinates_update.html
updatedb(lat,lng,street); //all declared and working

passitalong.js
$.get("dbquery.php", {latitude: lat}, {longitude: lng}, {id:street} );


qbquery.php
<?php 
$longitude = $_GeT['longitude'];
$latitude = $_Get['latitude'];
$street= $_Get['id'];
echo "test";
echo $street;



?>

Any clue what is wrong?

2 Answers 2

1

This is how you do it:

$.get("dbquery.php", {'latitude': lat, 'longitude': lng, 'id':street});

But of course you need to make sure that lat, lng, and street has a value in it before you pass it on the $.get method.

And to make your code cleaner use: $_GET['latitude'] not $_Get['latitude']

And here's a reference from nettuts on how to perform ajax calls in jquery

Oh and in case you want to do something once the data is submitted, you can also include a callback function:

 $.get("dbquery.php", {'latitude': lat, 'longitude': lng, 'id':street}, function(data){
    //do something with data
 });

Of course you need to have something like:

echo "something";

On dbquery.php if you want to output something after the data has been submitted.

Sign up to request clarification or add additional context in comments.

Comments

0

It should be $_GET. PHP variables are case sensitive. The script is probably dying because $_Get is undeclared.

2 Comments

I tried that, nothing changed. THough thanks for pointing it out as it would cause trouble down the road. Dumb question but what should I expect to happen? Should a new tab open with the echo statements printed? Should they appear in the html file?
You need a success function in the jQuery code to do what you want with what is returned. See api.jquery.com/jQuery.get

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.