Richard Zilahi
Richard Zilahi

Reputation: 692

Ajax success returning object Object

I have reviewed the other topics, but so far i have not found any solutions. I know i am doing something wrong..

here is my php:

header("Content-Type: application/json", true);
echo json_encode((object)array(
    "content" =>
        $emailAddress
));

and my ajax success part:

jQuery.ajax({
                type: "POST", // HTTP method POST or GET
                url: "getemailaddress.php", //Where to make Ajax calls
                dataType:"json", // Data type, HTML, json etc.
                data:myData, //Form variables
                success:function(response){
                    $("#emailtoinvite").val($(response.content))
                },
                error:function (xhr, ajaxOptions, thrownError){
                    //display error message here
                }
            });

my input box gets the following value:

[object Object]

do you have any suggestion how to solve the problem? thanks!

Upvotes: 0

Views: 674

Answers (1)

zerkms
zerkms

Reputation: 254886

That's what exactly you ask to do:

$(response.content)

is an expression that returns an instance of jquery object that performed lookup over a CSS selector specified in response.content variable.

What you actually need is:

$("#emailtoinvite").val(response.content)
                       ^--- a plain value, not a `$` function call

Upvotes: 3

Related Questions