开发者

Passing values from ajax page to calling page javascript function

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 va开发者_JAVA百科lue 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...


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"}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜