jQuery UI对话框窗体-缺少变量值


jQuery UI dialog form - Missing variable values

在我的网站上,我正在用jQuery ui框架制作一个对话框表单。

该对话框请求一个主题、查看内容、名称和城市,这些内容应插入mySQL中。然而,当我想将变量传递给PHP时,变量中没有值。

以下是处理对话框的整个js函数:

$( "#dialog-form" ).dialog({
    autoOpen: false,
    height: 600,
    width: 550,
    modal: true,
    buttons: {
        "Skriv Review": function() {
            var bValid = true;
            allFields.removeClass( "ui-state-error" );
            bValid = bValid && checkLength( topic, "topic", 3, 16 );
            bValid = bValid && checkLength( review, "review", 1, 10000 );
            bValid = bValid && checkLength( name, "name", 1, 25 );
            bValid = bValid && checkLength( city, "city", 1, 16 );
            bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Bruger skal være a-z, 0-9, underscores, begynde med et bogstav." );
            if ( bValid ) {
                $( "#users tbody" ).append( "<tr>" +
                    "<td>" + topic.val() + "</td>" + 
                    "<td>" + review.val() + "</td>" + 
                    "<td>" + name.val() + "</td>" +
                    "<td>" + city.val() + "</td>" +
                "</tr>" ); 
                var data = {
                    topic: topic.val(),
                    review: review.val(),
                    name: name.val(),
                    city: city.val()
                }
                $.ajax({
                    type : 'POST',
                    url : 'bruger-reviews.php',
                    dataType : 'json',
                    data: data,
                    success : function(data){
                        //success
                    }
                });
                $( this ).dialog( "close" );
            }
        },
        Cancel: function() {
            $( this ).dialog( "close" );
        }
    },
    close: function() {
        allFields.val( "" ).removeClass( "ui-state-error" );
    }
});

以下是我如何接收PHP中的数据:

$ins_topic = $_POST['topic'];
$ins_review = $_POST['review'];
$ins_name = $_POST['name'];
$ins_city = $_POST['city'];

我可以像在jQueryUI的演示中那样显示值。

当我$_GET或$_POST变量时没有数据。为什么我不可能将这些值传递给PHP?还有其他方法我可以试试吗?

谢谢。

在关闭对话框之前,您应该将值带到一个或多个对象中。

此代码从DOM中删除对话框;$(this).对话框("关闭");

使用此;

if ( bValid ) {
$( "#users tbody" ).append( "<tr>" +
"<td>" + topic.val() + "</td>" + 
"<td>" + review.val() + "</td>" + 
"<td>" + name.val() + "</td>" +
"<td>" + city.val() + "</td>" +
"</tr>" ); 
var data = {
    topic: topic.val(),
    review: review.val(),
    name: name.val(),
    city: city.val()
}
$( this ).dialog( "close" );

而不是在ajax请求上使用此数据对象

$.ajax({
                        type : 'POST',
                        url : 'bruger-reviews.php',
                        dataType : 'json',
                        data: data,
                        success : function(data){
                            //success
                        }
                    });