gpt4 book ai didi

javascript - ajax post 不适用于 ajax get from inside div

转载 作者:行者123 更新时间:2023-12-03 08:09:48 25 4
gpt4 key购买 nike

我正在开发一个客户管理系统,目前我遇到了一个问题,我已经尝试解决了一周,但现在已经没有想法了

我有index.php,基本上它是一个简单的表单,您提交客户的名字和姓氏,然后ajax将请求发送到functions2.php以添加到数据库,然后报告成功与否,然后webapp_get_customers检索并更新表新客户进入 webapp_get_customers div,无需刷新页面,这工作正常

但是在 get.php 页面上,我有一个表,它从表中选择结果,然后添加下面相同的表单,以便当我在索引页面上编辑时能够编辑客户名称,它以模式正确打开表单,但是不是没有提交表单,就像找不到ajax

所以我所追求的是如何让它查看 webapp_get_customers div 以查看表单是否已提交或者我是否将这一切都错了。我认为浏览器无法看到位于 get.php 页面上的 div 内的代码,它只是返回加载的内容

请帮助它,非常感谢

<form  name='frm_details' class='frm_details' id='frm_details0' action=''>
<input type='text' class='form-control' name='cu_fname' required>
<input type='text' class='form-control' name='cu_lname' required>
<input type='submit' value='Save' >
</form>

<script>
$(function() {
$('form.frm_details').on('submit', function(event) {
event.preventDefault();
$.ajax({
url: '/limitless/functions2.php',
type: 'post',
dataType: 'json',
data: $(this).serialize(),
success: function(data) {
if(data.status == '1')
{
$('#info').addClass('alert alert-danger no-border').html(data.message);
}
if(data.status == '2')
{
$('#info').addClass('alert alert-danger no-border').html(data.message);
}
}
});
});
});
</script>

<script>
function webapp_get_customers(){
$.ajax({
type: 'GET',
url: '/limitless/get.php',
dataType: 'html'
}).done(function( data ) {
$('#webapp_get_customers').html(data);
});
}
webapp_get_customers();
</script>


<div id='webapp_get_customers'></div>

最佳答案

你只需要从函数中删除send jquery ajax函数,并以这种方式调用它:

<form  name='frm_details' class='frm_details' id='frm_details0' action=''>
<input type='text' class='form-control' name='cu_fname' required>
<input type='text' class='form-control' name='cu_lname' required>
<input type='submit' value='Save' >
</form>

<script>
$(function() {
$('form.frm_details').on('submit', function(event) {
event.preventDefault();
$.ajax({
url: '/limitless/functions2.php',
type: 'post',
dataType: 'json',
data: $(this).serialize(),
success: function(data) {
if(data.status == '1')
{
$('#info').addClass('alert alert-danger no-border').html(data.message);
}
if(data.status == '2')
{
$('#info').addClass('alert alert-danger no-border').html(data.message);
}
}
});
});
$.ajax({
type: 'GET',
url: '/limitless/get.php',
dataType: 'html',
success: function(data)
{
//alert(html);
$('#webapp_get_customers').html(data);
}
});

});
</script>

<div id='webapp_get_customers'></div>

关于javascript - ajax post 不适用于 ajax get from inside div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34196878/

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