Jump to content

Pass a JSON object via an AJAX call


blirette

Recommended Posts

Hi all,

 

I'm pretty new to using this JSON thing and would like to know why this isn't working.

 

I'm trying to get via AJAX some infos that I'd like to be formatted in JSON so I can parse them easily. A PHP page is generating this string :

 

{"lastName":"Hope","firstName":"Bob","email":"bobhope@hotmail.com"}

 

I'm trying to retrieve it from another PHP page via this :

 

var aInfos = xmlhttp.responseText;

alert(aInfos.firstName);
alert(aInfos.lastName);
alert(aInfos.email);

 

But it doesn't seems to work. It says "undefined".

 

When I replace "xmlhttp.responseText" with "{"lastName":"Hope","firstName":"Bob","email":"bobhope@hotmail.com"}", it works.

 

What am I missing?

 

Thanks for your time and have a nice day!

Link to comment
https://forums.phpfreaks.com/topic/200302-pass-a-json-object-via-an-ajax-call/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.