admin管理员组文章数量:1406968
I trying to display the content of a MySQL TEXT field inside a <pre></pre>
html markup.
To acplish 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 e 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
I trying to display the content of a MySQL TEXT field inside a <pre></pre>
html markup.
To acplish 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 e 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
- use trim() to remove extra whitespaces – Nishu Tayal Commented Dec 18, 2013 at 8:55
2 Answers
Reset to default 7make sure that your server side php file does not have any spaces before the php open tags and if possible do not use '?>'-tags to prevent trailing spaces aswell
try jQuery.trim() or replace()
var newAnswer = data.replace(" ", "");
$("#configFile").html(newAnswer );
本文标签: javascriptAjax call or php script add spaces to my data resultStack Overflow
版权声明:本文标题:javascript - Ajax call or php script add spaces to my data result - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744957107a2634422.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论