Chiunque può dirmi perché sto ottenendo questo errore:Jquery Uncaught TypeError: Impossibile leggere la proprietà 'sostituire' di indefinito
Uncaught TypeError: Impossibile leggere la proprietà 'sostituire' di indefinito
function checkNewPost(x) {
var pid = $('#NewPostbody').attr('class');
if(pid === 'post-t') {
setTimeout(checkNewPost, <?php echo $p_id; ?>);
} else {
$.ajax({
type: "POST",
url: "/html_postReply.php",
data: "pid="+pid.replace('post-t', '')+"&type=1",
success: function(html) {
if(html) {
$('.tekin').append(html);
jQuery("span.timeago").timeago();
$(".tekin").scrollTop($(".tekin")[0].scrollHeight);
}
if(!x) {
setTimeout(checkNewPost, <?php echo $p_id; ?>);
}
}
});
}
}
checkNewPost();
Significa solo che 'pid' è' indefinito'. – Pointy
Se è possibile utilizzare un fallback (ad esempio la stringa vuota), è possibile utilizzare l'operatore '||': 'var pid = $ ('# NewPostbody'). Attr ('classe') || ''; '. – Xufox
Ti opporresti se avessi modificato il tuo titolo e i tag? Questo onestamente non ha nulla a che fare con jQuery. È un messaggio di errore JavaScript standard causato da un valore 'indefinito' ... – War10ck