Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在确认弹出窗口后使用ajax/jquery发布数据_Php_Javascript_Jquery_Ajax - Fatal编程技术网

Php 如何在确认弹出窗口后使用ajax/jquery发布数据

Php 如何在确认弹出窗口后使用ajax/jquery发布数据,php,javascript,jquery,ajax,Php,Javascript,Jquery,Ajax,我想在弹出确认消息并且用户单击ok时,从表单中的隐藏输入类型发送一个id。现在我甚至不能使这个代码没有确认弹出工作,没有错误,只是刷新,什么也没有发生。您可能会想,为什么我需要确认向购物车添加项目,但那是因为我以后还需要从数据库中删除项目 <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(document).rea

我想在弹出确认消息并且用户单击ok时,从表单中的隐藏输入类型发送一个id。现在我甚至不能使这个代码没有确认弹出工作,没有错误,只是刷新,什么也没有发生。您可能会想,为什么我需要确认向购物车添加项目,但那是因为我以后还需要从数据库中删除项目

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">

$(document).ready(function(){
$('#add').click(function(){
var id = $("#get_id").val()

$.confirm({
        'title'     : 'Delete Confirmation',
        'message'   : 'You are about to delete this User.Continue?',
        'buttons'   : {
            'Yes'   : {

                'action': function(){$a.ajax({
url: 'http://localhost/com/index.php/shopping_basket/view_basket',
type: 'POST',
data: { id: id },
    success: (function(){
    alert('added' + id);

});
                }


            },
            'No'    : {

                'action': function(){}  // Nothing to do in this case. You can as well omit the action property.
            }
        }
    });

});
});
</script>
形式

<form id="basket" method="post" action="">
<input type="hidden" id="get_id" value="<?php echo $id ?>">
<input type="submit" id="add" value="Add">
</form>
顺便说一句,使用window.location.href而不是这个发送东西有什么区别?

不包含任何没有回音的内容-正如前面所指出的,您还是忘了给它命名:

<input type="hidden" name="whatsmyname" value="<?php echo $id ?>">
如果没有回音,将不会包含任何内容-正如所指出的,您无论如何都忘了给它命名:

<input type="hidden" name="whatsmyname" value="<?php echo $id ?>">

有很多事情要做

我把echo放在这里


4最后,您不能为表单元素提供单击功能,请将其更改为submit(提交)

有很多事情要做

我把echo放在这里

4最后,您不能为表单元素提供单击功能,请将其更改为“提交”

尝试以下操作:

下载js文件

jquery.confirm.js

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="jquery.confirm.js"></script>
$(document).ready(function(){
$('#add').click(function(){
var id = $("#get_id").val()

$.confirm({
            'title'     : 'Delete Confirmation',
            'message'   : 'You are about to delete this User.Continue?',
            'buttons'   : {
                'Yes'   : {

                    'action': function(){$a.ajax({
    url: 'http://localhost/com/index.php/cart/add_cart',
    type: 'POST',
    data: { id: id }
        success: (function(){
        alert('added' + id);

    });
                    }


                },
                'No'    : {

                    'action': function(){}  // Nothing to do in this case. You can as well omit the action property.
                }
            }
        });

});
});
<form id="basket" method="post" action="">
<input type="hidden" id="get_id" value="<?php echo $id ?>">
<input type="submit" id="add" value="Add">
</form>
试试这个:

下载js文件

jquery.confirm.js

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="jquery.confirm.js"></script>
$(document).ready(function(){
$('#add').click(function(){
var id = $("#get_id").val()

$.confirm({
            'title'     : 'Delete Confirmation',
            'message'   : 'You are about to delete this User.Continue?',
            'buttons'   : {
                'Yes'   : {

                    'action': function(){$a.ajax({
    url: 'http://localhost/com/index.php/cart/add_cart',
    type: 'POST',
    data: { id: id }
        success: (function(){
        alert('added' + id);

    });
                    }


                },
                'No'    : {

                    'action': function(){}  // Nothing to do in this case. You can as well omit the action property.
                }
            }
        });

});
});
<form id="basket" method="post" action="">
<input type="hidden" id="get_id" value="<?php echo $id ?>">
<input type="submit" id="add" value="Add">
</form>

AJAX在浏览器和web服务器之间使用异步数据传输HTTP请求,允许网页从服务器请求少量信息而不是整个页面,而无需重新加载网页。AJAX在浏览器和web服务器之间使用异步数据传输HTTP请求,允许网页从服务器请求少量信息,而不是整个网页,而无需重新加载网页。这正是我想要的,但我甚至没有得到确认窗口。更新了,你能看一下吗?这正是我要找的,但我甚至没有得到一个确认窗口。更新了,你能看一下吗?
var id = $("#id").val();
$a.ajax({
    url: 'http://localhost/com/index.php/cart/add_cart',
    type: 'POST',
    data: { id: id }
        success: (function(){
        alert('added' + id);

});
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="jquery.confirm.js"></script>
$(document).ready(function(){
$('#add').click(function(){
var id = $("#get_id").val()

$.confirm({
            'title'     : 'Delete Confirmation',
            'message'   : 'You are about to delete this User.Continue?',
            'buttons'   : {
                'Yes'   : {

                    'action': function(){$a.ajax({
    url: 'http://localhost/com/index.php/cart/add_cart',
    type: 'POST',
    data: { id: id }
        success: (function(){
        alert('added' + id);

    });
                    }


                },
                'No'    : {

                    'action': function(){}  // Nothing to do in this case. You can as well omit the action property.
                }
            }
        });

});
});
<form id="basket" method="post" action="">
<input type="hidden" id="get_id" value="<?php echo $id ?>">
<input type="submit" id="add" value="Add">
</form>