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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.