我想在主(父)窗口中访问 iframe 的内容..使用 jQuery
<iframe id="epsresponse" name="epsresponse" src="js/demo.json">
</iframe>
<button>click</button>
<div id="atg_store_storedCreditCards">
</div>
</div>
我正在尝试使用 Ajax jQuery 添加单独的 JSON 文件,它工作正常,当 JSON 数据在 iframe 内呈现时,我需要同样的东西。
<script>
$(document).ready(function(){
window.onload=function() {
var iframeContent = $('#epsresponse').html();
console.log(iframeContent);
};
$('button').live('click', function(){
$.ajax({
type:'GET',
url: 'js/demo.json',
dataType:'json',
cache:false,
success: function(data){
if(data.status == "success"){
console.log(data.nickname);
console.log(data.token);
console.log(data.expirationMonth);
console.log(data.expirationYear);
console.log(data.nameOnCard);
console.log(data.creditCardNumber);
console.log(data.creditCardType);
$('#atg_store_storedCreditCards').append('<div class="atg_store_storedCreditCards"><div class="nickname">'+data.nickname+'</div><div class="token">'+data.token+'</div><div class="expirationMonth">'+data.expirationMonth+'</div><div class="expirationYear">'+data.expirationYear+'</div><div class="nameOnCard">'+data.nameOnCard+'</div><div class="creditCardNumber">'+data.creditCardNumber+'</div><div class="creditCardType">'+data.creditCardType+'</div></div>');
//<div class="token">'+data.token+'</div><div class="expirationMonth">'+data.expirationMonth+'</div><div class="expirationYear">'+data.expirationYear+'</div><div class="nameOnCard">'+data.nameOnCard+'</div><div class="creditCardNumber">'data.creditCardNumber+'</div><div class="creditCardType">'data.creditCardType+'</div>
//$('#nickname').html('+ nickname +');
}
},
error: function(status){
console.log(status);
}
});
});
});
</script>