Jono_2007
Jono_2007

Reputation: 1046

Getting data via JSON using jQuery

I have a website, where once a button is clicked it will trigger some javascript actions. I want to get some data via a php script i have written. I am using this method:

$.get("get_uni_info.php?addressToSearch=" + address, address, function(myData)
{
    $.each(myData, function(key, value) 
    {
        console.info(value);
    })
}, "json");

Inside the php code I am trying to get the value "address" to be able to search my database and send back some data but everything I just get nothing returned. I have test to the php code and it will return data if artificial measures are put in place so I can tell its not my PHP code.

Am i going wrong in my jQuery?

Upvotes: 0

Views: 117

Answers (1)

VisioN
VisioN

Reputation: 145398

Possibly the problem is in usage of $.get method.

You should write either

$.get("get_uni_info.php?addressToSearch=" + address, function(myData) {
    ...
}, "json");

or

$.get("get_uni_info.php", { addressToSearch : address }, function(myData) {
    ...
}, "json");

PHP code should handle address as:

$address = $_GET['addressToSearch'];

EDIT: If this does not help, we need to have a look at your PHP code (the response part precisely) to know where is the exact problem.

Upvotes: 1

Related Questions