0

im using the function below to get image names. I also use the json code to get data of a different url, but somehow it isnt working at this. (im new to javascript. Just writing php normally.

function getImgname(name) {
        $.getJSON("http://url.com/info.php?name="+name, function(json321) {
       return json321.js_skininfo;
     });
}
myusername123
  • 49
  • 1
  • 6
  • 1
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – James Jun 07 '17 at 21:04

2 Answers2

0

Try this:

function getImgname(myName) {
    $.ajax({
        url: 'http://url.com/info.php',
        data: {
            name: myName
        },
        type: 'POST',
        dataType: 'json',
        success: function(data) {
            // do what you want with your data
            return data.js_skininfo;
        }
    });
}
Tom el Safadi
  • 6,164
  • 5
  • 49
  • 102
0

I tried this now:

function getImgname(myName) {
                        $.ajax({
                            url: "http://url.com/ninfo.php",
                            type: 'POST',
                            dataType: 'json',
                            success: function (data) {
                                return data.js_skininfo;
                            },
                            error: function () {
                            }
                        });
}

This isnt working (undefinied), but if i alert the data.js_skininfo it shows me the correct value.

myusername123
  • 49
  • 1
  • 6