Php $.post结果回显HTML而不是值
这里有一个简单的问题。我获取HTML元素的值,并使用以下代码通过POST将其发送到服务器。但是当我提醒结果而不仅仅是值时,我也会得到包含的PHP文件的HTML。为什么会这样Php $.post结果回显HTML而不是值,php,html,ajax,post,Php,Html,Ajax,Post,这里有一个简单的问题。我获取HTML元素的值,并使用以下代码通过POST将其发送到服务器。但是当我提醒结果而不仅仅是值时,我也会得到包含的PHP文件的HTML。为什么会这样 function postData(){ let select_value = document.getElementById("selector").value; $.post('customer_order_form.php', { valor: select_value }, function(result)
function postData(){
let select_value = document.getElementById("selector").value;
$.post('customer_order_form.php', { valor: select_value }, function(result) {
alert(result);
});
}
PHP代码非常简单,只是为了测试目的重复了数量:
<?php include('includes/header.html');
if (isset($_POST["valor"]))
{
$quantity = $_POST["valor"];
echo $quantity;
}
else
{
$quantity = null;
echo "no quantity here";
}
?>
但是在回调函数中,当我警告结果时,我得到的是所有包含的文件HTML代码,而不是值,这是为什么
包括“includes/header.html”;正在向页面添加HTML。当您执行$.post时,您正在检索头文件。此包含不应包含在您的文件中
删除include,一切都会好起来。我想这与include'includes/header.html'有关;。非常感谢,先生