I have detected broken images and getting broken src's and store them into the object but unable to store them into an object because of I think there is a time difference between error function and catching them into object please check my code.
I successfully get src but unable to store them in object variable and passing them into backend via ajax. By debugging testing it I think
brokenImages.current_url = currentUrl;
brokenImages.broken_src = brokenSrc;
Run before error function and I get nothing in brokenImages variable.
jQuery(document).ready(function($){
//Check Image Error
var i = 0;
var currentUrl = window.location.href;
var brokenImages = new Object();
var brokenSrc = new Object();
$('img').on('error', function(event){
var link = event.target.src;
console.log('check '+link + ' num ' + i);
brokenSrc[i] = link;
i++;
});
//alert(brokenSrc);
//Like if I put alert brokenSrc object here I get them in ajax and php
console.log(' broken src ');
console.log(brokenSrc);
brokenImages.current_url = currentUrl;
brokenImages.broken_src = brokenSrc;
console.log( ' broken images ' );
console.log(brokenImages);
//In console log of chrome and firefox I can see object and srcs in them but when ajax sending them and catching them into php there is nothing broken_src
//Sent Script Data
$.ajax({
type: "POST",
url: ajax_url,
data: {
imageData: brokenImages
},
success: function(result){
console.log(result);
}
});
});
Unable to store them in brokenImages variables while successfully getting them.
error()call without checking the docs first? That's really not how stackoverflow works. Asking a question should be the absolute last resort. jsfiddle.net/4n3f3sbr/1