gpt4 book ai didi

javascript - 使用 AJAX 将变量从 jQueryUI 对话框发布到 PHP

转载 作者:行者123 更新时间:2023-11-28 07:23:28 24 4
gpt4 key购买 nike

我正在尝试从对话框窗口中的输入文本字段获取输入,以将它们用于 SQL 查询。

我的问题是我无法在 PHP 中使用数组。我没有收到任何错误或成功消息。在 Firefox 的网络日志中,我可以看到具有正确值的 Post 方法。

这是我的 js 代码片段:

<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']);

?>

不知道我做错了什么,并对我糟糕的英语和代码中的德语单词感到抱歉。感谢您的帮助

最佳答案

使用下面的代码片段

         buttons: {
"Quelle hinzufügen": function() {
var out = [];
out.push(document.getElementById("titelin").value);
out.push(document.getElementById("autorin").value);
out.push(document.getElementById("tagsin").value);
out.push(document.getElementById("linkin").value);
ajax(out);
},

还有

        function ajax(info){

$.ajax({
type:"POST",
url:"quellenverzeichnis.php",
data: {output: info},
success: function(data){
alert("works"+data);
},
error: function(){
alert("fail");
}
});
};

还有

        $_POST['output']

关于javascript - 使用 AJAX 将变量从 jQueryUI 对话框发布到 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30030488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com