0

In my project i create an object when an input text blur like this:

inputT1.onblur = function(){
            var pDomain = this.value;
            if (pDomain.substring(0,4) === "http") {
                var getLocation = function(href) {
                    var l = document.createElement("a");
                    l.href = href;
                    return l;
                    };
                var l = getLocation(pDomain);
                pDomain = l.hostname;

            }

            responseT = $.get( "neuroscan/php/trial500.php", { P1: 'dominio', P2: pDomain } );
            console.log("Status: "+responseT.responseText);

            }

Console respond Status: undefined and if i write:

console.log("Status: "+JSON.parse(responseT.responseText));

return an error. The object responseT was create (as you can see from the picture) and responseText have a value, but I can't isolate it into a variable

enter image description here

Any idea?

Thanks in advance

4
  • 1
    possible duplicate of How to return the response from an Ajax call? Commented Nov 7, 2014 at 9:58
  • I read that post but my problem is that despite the existence of the object responseT if I write responseT.responseText console me back "undefined" Commented Nov 7, 2014 at 10:02
  • responseText filled when request become complected. So when you call console.log at first time - it is undefined. But it filled later Commented Nov 7, 2014 at 10:04
  • Your problem is that you're testing them at different times. When you type "responseT" in the console it has already been resolved. But when you have responseT.responseText in the code, it hasn't been resolved yet and you're accessing promise. The duplicate will solve your problem. Commented Nov 7, 2014 at 10:05

1 Answer 1

1

$.get return promise, not data. Thus it work ansyncroniusly

inputT1.onblur = function(){
        var pDomain = this.value;
        if (pDomain.substring(0,4) === "http") {
            var getLocation = function(href) {
                var l = document.createElement("a");
                l.href = href;
                return l;
                };
            var l = getLocation(pDomain);
            pDomain = l.hostname;

        }

         $.get( "neuroscan/php/trial500.php", { P1: 'dominio', P2: pDomain }, function(data, status, xhr){
                 console.log(data);
               });
        }
Sign up to request clarification or add additional context in comments.

Comments

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.