【发布时间】:2012-08-28 13:35:05
【问题描述】:
在我的网站上,我正在使用 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'];
我没有问题像在 jQuery UI 的演示中那样显示值。
当我 $_GET 或 $_POST 变量时没有数据。为什么我无法将值传递给 PHP?有没有其他方法可以试试?
谢谢。
【问题讨论】:
-
你能附上你的完整的javascript代码吗?因为你的问题还不清楚,如有必要也附上你的php
-
bungdito,我已经附上了整个js函数和PHP。
-
我尝试使用json_decode方法访问数据,但还是没有。
标签: php javascript ajax jquery-ui dialog