471,859 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,859 software developers and data experts.

IFrame - getting the JSON response

Hi all,

I am currently working with Iframe which holds the JSON response from the server once when the picture gets uploaded successfully. Now I need to parse the JSON response and retrieve the id of the image uploaded.

My Iframe is here

Expand|Select|Wrap|Line Numbers
  1. <iframe id="PUIFrame"
  2.   name="PUIFrame"
  3.   style="width:300px; height:200px; border: 5px;" src="blank.html">
  4.   </iframe>
The response is of the form

Expand|Select|Wrap|Line Numbers
  1. {picture: {content_type: "image/jpg", name: "SliderPuzzle", id: 58}, caption: "", id: 58}
I am able to view the response from the server. I need some ways to get the image id.

I got stuck up with this.

Any help would be greatly appreciated.

With thanks,
Jul 26 '07 #1
4 9468
5,390 Expert Mod 4TB
hi ...

assuming that you know how to use your responseText, try the following:

Expand|Select|Wrap|Line Numbers
  1. // eval the json-string to an native js-object
  2. // what is the origin. purpose of json at all
  3. var response = eval(request.responseText);
  5. // now you may use the typical reference methods for
  6. // objects or arrays like:
  7. var img_id = response.id;
kind regards
Jul 26 '07 #2
5,821 Expert 4TB
Heya, Amutha. Welcome to TSDN!

I award 12 points for creative use of [i] tags. Unfortunately, I have to deduct 12 points for using [i] tags when you should have used [code] tags.

Better luck next time.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Jul 26 '07 #3
Hi all,

Thanks for your replies. I would post the code in [code]

I am not using AJAX for posting the request. In my case my form's target
points to an IFrame and so the response is received in the IFrame.
I tried invoking a function to get the response and then parse it for
the Image id.

Is there any way to proceed with this?

With thanks,
Jul 27 '07 #4
5,390 Expert Mod 4TB
hi ...

i showed you already. retrieve the string you showed in your original post from your iframe and use use the things i showed ... that will do the job. doesn't matter to use ajax or not ... you always can eval the json-string when you have it ... in your case you would simulate it ... when you hide your iframe ;) ... typically we use that as an fallback option when no XMLHttpRequest-Object is available ... please, ask more questions in case i didn't make myself very clear ...

kind regards
Jul 27 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

16 posts views Thread by G Matthew J | last post: by
20 posts views Thread by Luke Matuszewski | last post: by
2 posts views Thread by pgnPoster | last post: by
2 posts views Thread by Ralph | last post: by
5 posts views Thread by pbd22 | last post: by
1 post views Thread by dan.goyette | last post: by
3 posts views Thread by Kelicula | last post: by
5 posts views Thread by najmi | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.