I have this ajax code:
function send(obj) {
var paket = {
Url: obj
}
$.ajax({
url: 'submit',
type: 'POST',
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(paket),
success: function (data) {
var iframe = document.getElementById('frame');
var html = data.msg;
iframe.src = 'data:text/html;charset=utf-8,' + encodeURI(html);
renderat = true;
$('frame').ready(function () {
console.log("laddad");
test();
});
},
error: function (data) {
}
})
}
Which works fine, it renders the html in my iframe:
<iframe width="600" height="600" id="frame"></iframe>
And then I use this to be able to pickup what elements are being used inside the iframe:
function test() {
if (renderat == true) {
console.log("0");
var framen = document.getElementById('frame').contentWindow;
$(framen).click(function (event) {
alert($(event.target).val());
});
}
}
The problem is that it only runs up to console.log("0") and then nothing happens.. Why? I suspect the problem lies in that i cant figure out how to put this jquery code inside of $(document).ready?
Any suggestions? Thanks