Hallo, ich versuche gerade mit Ajax Bildbreite zu messen. Leider funktioniert es nicht wirklich gut. Ich bekomme immer den richtigen Wert wenn ich zweimal geklickt habe, erstes mal bekomme ich Wert: 0.
Weiß jemand warum??? Vielen dank.
Weiß jemand warum??? Vielen dank.
PHP-Code:
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Prüfe Breite</title>
<style>
#{ margin:0px auto; }
</style>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
var id = '1';
$('#button').click(function() {
$.ajax({
dataType:"html",
type: "POST",
cache:false,
async: true,
data: "seite=" + id,
url: "verzeichnis/script.php",
success: function(breite) {
$("#result").html(breite);
var width = $('#result img').width();
alert(width);
}
});
}); });
</script>
<p id="button">Click here</p>
<div id="result"></div>
</body>
</html>
Kommentar