如何从jquery确认框提交php页面

How to submit the php page from jquery confirmation box?

本文关键字:提交 php 页面 确认 jquery      更新时间:2023-09-26

我从jquery创建了一个确认框。我想在单击确认框中的确认按钮时提交页面并查看PHP echo消息。你能帮我输入确认按钮的代码吗?

我的jQuery/javascript函数在这里:

$(document).ready(function(){
   $('#click').click(function(){
//$(function() {
    // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
    $( "#dialog:ui-dialog" ).dialog( "destroy" );
    $( "#dialog-confirm" ).dialog({
        resizable: false,
        height:140,
        modal: true,
        buttons: {
            "Ok": function() {
        // I WANT THE CODE FOR HERE TO SUBMIT THE PAGE TO WIEW PHP ECHO MESSAGE 
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        }
    });
});
});

您可以使用jQuery Form提交库。这将给你很多选择。根据您的要求,您可以致电

beforeSubmit: 'YOUR FUNCTION To OPEN DIALOG',

如果这是真的,你的表格将得到张贴,你肯定会得到回复。请参阅此处的示例:http://malsup.com/jquery/form/#ajaxForm

使用jQuery Post函数。。。

$.post("test.php", { 'choices[]': ["Jon", "Susan"] });

这是一个在帖子完成时带有回调的版本。。。

$.post("test.php", { name: "John", time: "2pm" },
   function(data) {
     alert("Data Loaded: " + data);
   }
);

或者,如果您有一个想要发布的现有表单,请使用jQuery提交函数。。。

$("form").submit();

但在执行此操作之前,您需要确保已填充表单中的输入字段。

试试这个代码,

var parameter_1 = 'test';
var parameter_2 = 'test';
$.ajax(
        {
            type: "POST",
            url: "/submit_url.php",
            data: "parameter_1="+ parameter_1 +"& parameter_2 ="+ parameter_2,
            success: function(html)
            {
                   alert('Submitted');              
            }
        });