Ankündigung

Einklappen
Keine Ankündigung bisher.

PHP Float Variablen zu JavaScript

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • PHP Float Variablen zu JavaScript

    Hey,

    mal wieder ein Problem.
    Folgender Code:

    Datei 1 "ajax.php":
    PHP-Code:
    <?php
    $change 
    = array(floatval(4.5),floatval(4.7));
    echo 
    json_encode($change);
    ?>
    Datei 2
    Code:
    <html>
    	<head>
    	</head>
    	<body>
    		<script src="http://code.jquery.com/jquery-latest.js"></script>
    		<script>
    		var x;
    		var y;
            (function worker() {		
    	  $.get("ajax.php", function(data){
    	  var duce = jQuery.parseJSON(data);
    	   x = parseFloat(duce[0]);
    	  y = parseFloat(duce[1]);
    
    	console.log(x);
    	console.log(y);
     	
    	});
    	setTimeout(worker, 120);
    })();
    
    
    
    </script>
    
    	</body>
    </html>
    Ausgabe auf der Konsole:
    4
    4

    Ich möchte aber gerne:
    4.5
    4.7

    Kann mir da jemand helfen? Ich will einfach nur meine Float Variablen von
    php auf einer anderen Seite in javascript darstellen und das all 120 ms.

  • #2
    Bau mal ein
    PHP-Code:
    console.log(data); 
    mit ein um zu sehen was da wirklich reinkommt.

    Kommentar

    Lädt...
    X