tags:

views:

45

answers:

1

One part of my page is being loaded via ajax using jquery. For example this initial page has a name first.php. It has a div with it's innerHTML generated from ajax called script (for example ajax is calling second.php). Is it possible to pass some values from ajax executed script (second.php) to original site. I need to access this value from original site (the one calling second script via ajax) javascript function, and I don't want to use hidden fields.

For example, my site has some captcha that is being displayed and processed through ajax. I don't want to write captcha result to some hidden field and access it with original site javascript function because of possible javascript injection attack...

A: 

Since you call your secound.php script via ajax, you surely could read the result.

$.ajax({
  url: 'secound.php',
  success: function(data) {
    // now data contains the code returned by secound.php
  }
});

Now the most common way to return data from your secound.php script is returning it in JSon format. Then you could do someting like:

var obj = jQuery.parseJSON(data);
alert(obj.name);

For this example your secound.php needs to return

{"name":"John"}
JochenJung
Thank you! That solved my problem!
Zuhra
Then accept the answer :-) With the green check mark on the left of my post.
JochenJung