【发布时间】:2015-05-04 12:42:27
【问题描述】:
我正在尝试从对话框窗口中的输入文本字段中获取输入,以将它们用于 SQL 查询。
我的问题是我不能在 PHP 中使用数组。我没有收到任何错误或成功消息。 在 Firefox 的网络日志中,我可以看到具有正确值的 Post 方法。
这是我的 js 代码的 sn-p:
<script>
// open popup window "dialog"
$(function() {
$( "#dialog" ).dialog({
autoOpen: false ,
width: 1000,
buttons: {
"Quelle hinzufügen": function() {
var out = [document.getElementById("titelin"),document.getElementById("autorin"),document.getElementById("tagsin"),document.getElementById("linkin")];
var outv = [out[0].value,out[1].value,out[2].value,out[3].value];
ajax(outv);
},
Abbrechen: function() {
$( this ).dialog( "close" );
}
}
});
$( "#opener" ).click(function(e) {
e.preventDefault();
$( "#dialog" ).dialog("open");
});
});
// posting to PHP
function ajax(outv){
$.ajax({
type:"POST",
url:"quellenverzeichnis.php",
data: {output: outv},
sucess: function(){
alert("works");
},
error: function(){
alert("fail");
}
});
};
</script>
这是我的 PHP 代码:
<?php
if (isset($_POST['output'])){
hinzufuegen();
};
printf($_POST['output']);
?>
不知道我做错了什么,并为我糟糕的英语和代码中的德语单词感到抱歉。 感谢您的帮助
【问题讨论】:
-
data: {output: bla},这个 bla 是从哪里来的? -
为什么您的请求会变为空白,因为未定义的
bla不会发送output字段 -
printf($_Post['output']);错了你应该使用 printf($_POST['output']);
-
对不起,bla 的东西只是一个字符串而不是数组的测试
-
请输入实际代码,这样我们就不必朝不同的方向挖掘了
标签: javascript php ajax jquery-ui dialog