I have MVC architecture for my project and recently I got a weird problem. Whenever I try to respond the Ajax request with printing some output in PHP, I get 8 enter characters before my output. I noticed that it’s putting these characters when just I want to echo but I don’t know how these extra enters come when they’re not in the string that I try to output. I’ve checked all of my files encoding to make sure that they aren’t the problem. I even left the response empty to check whether there is some script earlier printing something or not but it wasn’t, the output was empty without any character.
Is there any tip?
Here’s my js:
$.ajax({
url: _baseRoot + '/admin/request',
type: 'post',
data: "req=" + req + args,
success: function(data)
{
var result = data.split(",");
var m_type = "";
switch(result[0])
{
case "error": m_type = "red"; break;
case "warning": m_type = "yellow"; break;
case "success": m_type = "blue"; break;
}
showMessage(m_type, result[1]);
}
});
Can’t really pinpoint it without seeing the backend, but as as most php project goes, those are probably comes from various included files that doesn’t mean to output anything but has a
?>and a newline at their end. The php interpreter just simply passes everything to the output that is not inside the<?php ?>tags.If you don’t want to output anything from a php file, you can remove closing
?>and the interpreter simply detects the end-of-file as the end-of-script, and it makes sure that no accidental whitespace creeps into the output from after?>.