PHP没有回显ajax发送的数据
你知道我的密码有什么问题吗?我以为会有用的。 我只想回显输入到div的数据,而不刷新网站。 Ajax发送了数据,但php没有显示它们,我真的不明白为什么PHP没有回显ajax发送的数据,php,jquery,Php,Jquery,你知道我的密码有什么问题吗?我以为会有用的。 我只想回显输入到div的数据,而不刷新网站。 Ajax发送了数据,但php没有显示它们,我真的不明白为什么 <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <scri
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function()
{
$(document).on("submit", ".form", function()
{
event.preventDefault();
$.ajax({
type: 'POST',
url: 'http://dev.nostools.cz/',
data: $('.form').serialize(),
success: function () {
//alert('form was submitted');
}
});
})
});
</script>
<div style="width: 250px; height: 100px;">
<div id="show" style="width: 100%; height: 80%; overflow-y: scroll; border: 1px solid black;">
<?php
if (isset($_POST['submit']))
{
echo $_POST['console']; //echo data or do something here
}
?>
</div>
<div style="width: 100%; height: 20%;">
<form class="form" method="post">
<input id="console" style="padding: 0; width: 67%;" type="text" name="console" />
<input style="padding: 0; width: 31%;" type="submit" name="submit" />
</form>
</div>
</div>
$(文档).ready(函数()
{
$(document).on(“submit”,“.form”,function()
{
event.preventDefault();
$.ajax({
键入:“POST”,
网址:'http://dev.nostools.cz/',
数据:$('.form')。序列化(),
成功:函数(){
//警报(“表格已提交”);
}
});
})
});
由于php是服务器端脚本语言,php脚本仅在服务器端运行。。。
在这里,您试图在客户端处理/运行php脚本,这不是正确的方法。。要显示数据,请在成功函数中进行以下更改
$.ajax({
type: 'POST',
url: 'http://dev.nostools.cz/',
data: $('.form').serialize(),
***success: function (data) {***
$("#show").html($("#console").val());
}
});
<?php
$_POST['console'];
//process your data.
echo $processed_data;
?>
$.ajax({
键入:“POST”,
网址:'http://dev.nostools.cz/',
数据:$('.form')。序列化(),
***成功:功能(数据){***
$(“#show”).html($(“#console”).val());
}
});
您无法向其他域发送帖子,您可能遇到了CORS错误。检查开发人员控制台。是否尝试将POST请求发送到同一页面,并假设它会立即出现?是的,我想显示数据。AJAX请求结果不会自动合并到页面中。。。您需要在成功回调中使用代码处理响应!所以,若我想通过php将修改后的数据显示回页面,并显示我必须做什么?您必须显示什么。。。?输入类型控制台的值我想将输入中的数据发送到php,然后“在php中编辑它们”,并显示它们,但如果您理解我的意思,则不刷新页面