javascript - Is there a way to retrieve an ajax response sent from an iframe? -


i wondering if there way retrieve response of ajax request sent iframe.

the iframe following:

  1. script in iframe sends ajax request
  2. iframe gets response, , updates content within iframe

what intercept request outside of iframe, , use information update page.

if go chrome's dev tools, , go network tab, can see request/response iframe makes. nice if there window event or similar triggers everytime response comes in on page.

note: iframe page not in same domain.

if child iframe in different domain parent, can't that's going work across browsers. see jasonjifly's answer below techniques work on browsers assuming have control on client scripts on both frames.

if parent , child on same domain, can achieve looking for.

for example, assuming you're using jquery, have code in iframe:

$.ajax(function() {    .....    complete: function() {        window.parent.onajaxcomplete('hi there');    } }); 

along code in parent frame:

function onajaxcomplete(msg) {     alert(msg); } 

to achieve similar results in cross-domain scenario have parent frame poll server. when server receives ajax request child iframe alert parent page via polling service. suitable if have control on services called child iframe.


Comments