I have a php script that returns 0.28. It is then extracted into HTML using AJAX and inserted into a range. The problem is that it is inserted with 5 spaces and appears to be on a new line. JQuery then sees this as a change and updates the existing range with a new value when there is no change. It seems like the space is not coming from php. I tried:
- to trim () and ltrim () php to get rid of spaces
- remove php exit tag
- coagulation in white space: discarding; in css and using an important tag (this is not readable, but a warning about chrome yellow on it).
- cropping a response using jquery
- using html notes to narrow the gap
Flushing php variable:
string(4) "0.28"
So my browser returns it
<span id="response1" style="display: inline;">*5spaceshere*
0.28</span>
This is my script.
$(function () {
function update() {
$.ajax({
type: "GET",
url: "balancefetch.php",
dataType: "html",
success: function (response) {
var trimmedResponse = $.trim(response)
if (trimmedResponse != $("#response1").html()) {
$("#response1").fadeOut(200, function () {
$("#response1").html(response);
$("#response1").fadeIn();
});
} else {}
}
});
}
setInterval(update, 5000);
update();
});
And my html
<div id="balance-div"><p class="balance">Balance<span id="response1">Loading...</span></p></div>
Php
$balance = ltrim($balance);
echo $balance;
$balance has 0.26