I trying to display the content of a MySQL TEXT field inside a <pre></pre>
html markup.
To accomplish that I use an ajax call
$.ajax({
type : 'POST',
url : webserviceFile,
data : {
action : "confFile",
id : id
},
success : function(data) {
$("#configFile").html(data);
},
error : function(e, f, g) {
return ("An error occure: " + e + "\n" + f + "\n" + g);
}
});
On server Side I have that piece of php :
switch($action) {
case 'confFile' :
$value = getConfigurationFile($_POST['id']);
echo "##$value##";
break;
}
Finally my orignal html file is :
<body>
<pre id="configFile" ondblclick='selectText( "configFile" )'></pre>
</body>
So the script does work, now my problem is that on Firefox IE8 and Chromium I have 3 spaces in front of my ajax result. For example, one of the file contains :
no config file
+ the two dashes I add to be sure that it does not come from my php script, in my <pre>
mark I will end up with :
<pre id="configFile" ondblclick="selectText( "configFile" )" class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 67px; max-height: 667px; height: auto;">
##no config##</pre>
And as you can see there's 3 spaces in front of my ##no config##
string.
I'm using the last stable jQuery and watching what the POST
return with Firebug I do see those spaces, I remove every echo or print in my php code except the one returning the ##no config##
but still those spaces appear.
Do you have any idea on how and why those fµµµµ appears, and do you know a work around for that ?
Thanks
Edit 1: Using trim is one solution but the content of the MySQL field is not modifiable and I can't remove white space at the end or at the beginning of that content for displaying.
Complete answer:
Remove every spaces before and after the php markup <?php
and ?>
in all you php files to avoid that behaviour that should do the trick