0

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?

3
  • 2
    What does console.log( myData ) say? Commented Apr 29, 2012 at 16:56
  • 1
    Maybe a duplication of Unable to return/process JSON in JQuery $.get() ? Commented Apr 29, 2012 at 16:58
  • FWIW, make certain that the data returned by the PHP code is valid JSON. I had a similiar problem some time back in that using getJSON I simply got nothing back without any error message. It turned out to be invalid JSON. Commented Apr 29, 2012 at 18:00

1 Answer 1

1

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.

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

1 Comment

I used the {} method and its worked a treat for this and other JSON requests i've made thanks

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.