I have a basic content swapper using JS and PHP. Everything was working fine until I noticed the script was echoing a number "1" after placing the results of the swap. There was no number one in my html, php includes, or scripts (that I could find.) Where the hell is it coming from and how can I get it to not appear.
JS
function swapContent(cv){
$("#workwrap").html(loadgif.gif).show();
var url = "includescripts/swapscript.php";
$.post(url,{contentVar:cv},function(data){
$("#workwrap").html(data).show();
});
}
PHP SCRIPT
<?php
$contentVar = $_POST['contentVar'];
if($contentVar == "logo"){
echo include("../workincludes/contA.php");
} else if($contentVar == "print"){
echo include("../workincludes/contB.php");
} else if($contentVar == "web"){
echo include("../workincludes/contC.php");
}
?>
HTML
<div id="content">
<div id="workwrap">
</div></div>
Remove echo
before include
call
, include
returns 1 on success
you don't need to echo
the include.
The '1's are the status true
(parsed as string) from successfully including the files.
For future if you get Ones or Zeores in the result, check if you tried to echo the result of a function.
Handling Returns: include returns FALSE on failure and raises a warning. Successful includes, unless overridden by the included file, return 1