0

I'm having a problem developing a script based on a user-data API.

I have created a function getUserData(username, what); and what it does is this;

var lasuniAPI = "script/data.php";
$.getJSON(lasuniAPI, { p: 'userdata', data: username}, function(data){
    return data.userdata.what;
});

I want 'what' to be defined but sadly I'm getting undefined returns.

Connor Simpson
  • 487
  • 1
  • 7
  • 27
  • possible duplicate of [How to return the response from an AJAX call from a function?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call-from-a-function) – Musa Feb 04 '13 at 00:08
  • If `what` is a variable, you need to use bracket notation as well. http://stackoverflow.com/q/4968406/1331430 – Fabrício Matté Feb 04 '13 at 00:18

1 Answers1

1

do this in your function:

console.log(data);

console.log() will tell you exactly what is in your return variable. (If you dont know where console.log() outputs information, read up on the developer tools. In chrome, go to View->Developer->Javascript console.

The other thing that will be valuable is the Network tab in Chrome's developer tools. It will tell you exactly what headers and variables are being sent to the server as well as what the server is responding with.

You may also want to ensure that the JSON string returned by the server is valid according to jsonlint.com.

Jared Green
  • 196
  • 1
  • 7