使用带有php的ajax传递值

时间:2016-11-18 13:38:33

标签: javascript php jquery ajax

我确定这是一个我在这里做的简单错误,但我无法发现它!

我有一个按钮,点击它时会打开一个新表单,相当简单,有两个输入字段。点击" Ok"我想提交该表单并将变量传递给同一页面中的php函数。

在页面的开头我有

$action = $_POST['add_audit'];

然后我的ajax看起来像这样:

function addAudit()
{
    $('#auditAddDialog').dialog('open');
}
$('#auditAddDialog').dialog({'autoOpen': false, 'modal' : true, 'buttons' : 
    [ { text: "Ok", click: function() {

        var auditDate = $('#datepicker').val();
        var e = document.getElementById("type");
        var auditType = e.options[e.selectedIndex].value;
        var add_audit = 'add_audit';
        var dialog = this;

        $.ajax({
            url: 'index_logged.php',
            dataType: 'json',
            data: {'add_audit':add_audit, 'auditDate' : auditDate, 'auditType' : auditType},
            type: 'post',
            timeout: 5000,
            success: function(json) { 
                if (json.status == 'S')
                    alert('New audit created!');

                    location.reload();
                    $( dialog ).dialog( "close" );

            },
            error: function() {}

        }); 

}}]});

起初,我在这里看不到任何错误,也不明白为什么它不应该起作用?但显然有一个错误,因为当我点击" OK"在表单上的按钮,我得到整个页面的HTML作为回应。

0 个答案:

没有答案