gpt4 book ai didi

javascript - JQuery 表单没有重新加载 : how to pass the $_POST info after success?

转载 作者:行者123 更新时间:2023-11-28 08:17:31 26 4
gpt4 key购买 nike

首先,下面的代码可以工作,但说实话,我不知道为什么:)经过多次尝试和错误后它才工作

我需要通过#filter-form提交$_POST数据,用于加载页面,因为action1函数将需要$_POST数据。

如果我删除+data或.html(data),它就不再起作用了。另外,如果我更改 url:"..."它也不再工作,我不明白为什么因为我不需要在这里做任何事情,我需要的只是加载此 page.php 页面并传递 $ _POST才能正常输出。

我的问题是,它为什么有效? (我想了解为什么放置 +data 或 html(data) 对于确保 $_POST 通过非常重要)以及如何使其更合适?感谢您的帮助

<script type="text/javascript">
$("#filter-form").submit(function(event) {
$.ajax({
type: "POST",
url: "includes/page.php?action=action1",
//Specify the datatype of response if necessary
data: $("#filter-form").serialize(),
success: function(data){
alert("succeess");
$("#tableresult").load("includes/page.php?action=action1"+data).html(data);
}
});
event.preventDefault();
return false;
});
</script>';

最佳答案

您根本不需要使用.load()。应该是:

success: function(data) {
alert("success");
$("#tableresult").html(data);
}

这将获取 AJAX 服务器返回的响应(应该是 HTML 代码),并将其放入 tableresult 元素中。

按照您的编写方式,您调用了服务器两次,这似乎不正确。

关于javascript - JQuery 表单没有重新加载 : how to pass the $_POST info after success?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23438745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com