I’m using some jquery/php to update a number when called through .load() function.
so lets say i have
<span id='draftCount'>1 Draft</span>
And the jquery I call to update it
$('#draftCount').load('countItems.php?cid=draftCount');
Now the inside of countItems.php
<?
include("connect.php");
mysql_select_db ("news");
$countWhat = $_GET['cid'];
if($countWhat == 'binCount') {
$pullBin = mysql_query("SELECT * FROM bin");
$count = mysql_num_rows($pullBin);
echo '$count';
}
if($countWhat == 'draftCount') {
$pullBin = mysql_query("SELECT * FROM `main` WHERE `active` < '2'");
$count = mysql_num_rows($pullBin);
if ($count == '1') $drafts = 'Draft';
if ($count != '1') $drafts = 'Drafts';
$count = "$count $drafts";
echo "$count";
}
?>
The result is
<span id="draftCount">
4 Drafts</span>
How do I get rid of all that whitespace above ‘4 Drafts’? What’s causing it?
Thanks!
You can create a trim function in javascript if you want, but I think that Pekka is probably right. Better to just not return whitespace.
You could also modify your response to return a json object with that text as a value. It won’t matter if there is whitespace before the declaration of the JSON object.