【发布时间】:2011-06-21 06:59:48
【问题描述】:
我发送到我的 PHP 的 jQuery 变量不起作用(或者至少,它似乎不起作用)。我已经用 ajax 将它发送到我的 php 中。
请看一下,或许能看出问题:
$('.do').click(function(){
var cid2 = $(this).attr('id');
var gebridauthpos = cid2.indexOf('||');
var gebridauth = cid2.substring(gebridauthpos+2);
$.post("agenda.php", {gebridauth: gebridauth});
alert(gebridauth);
<?php
if ($admin == true || isset($_POST['gebridauth']) AND $_SESSION['id'] == $_POST['gebridauth']) {
echo "$('#dialog').dialog('open');\n";
echo "var cid = $(this).attr('id');\n";
echo "var datum = cid.substr(0, 10);\n";
echo "var naampos = cid.indexOf('|');\n";
echo "var gebridpos = cid.indexOf('||');\n";
echo "var naam = cid.substring(naampos+1,gebridpos);\n";
echo "var gebrid = cid.substring(gebridpos+2);\n";
echo "$.ajax({\n";
echo "type: \"POST\",\n";
echo "url: \"agenda.php\",\n";
echo "data: naam,\n";
echo "success: function(){\n";
echo "$('#gebruikerinput').html(\"<input type='text' READONLY='' size='35' value='\" + naam +\"'>\");\n";
echo "$('#gebridinput').html(\"<input type='hidden' name='gebridtextbox' value='\" + gebrid + \"'>\");\n";
echo "$('#datuminput').html(\"<input type='text' READONLY='' size='12' name='datum' value='\" + datum + \"'>\");\n";
echo "}\n";
echo "})\n";
echo "return false;\n";
}
?>
});
基本上我想要做的是,当我点击 TD 时,在我的 PHP 的 if 语句中使用“gebridauth”。如果 TD 与登录的人相同,则显示对话框。
【问题讨论】:
-
响应 JS 的每一行 和 转义引号?读到这里很痛。
-
Agenda.php 是代码所在的当前 PHP。它基本上会生成一个包含数据的表格。
标签: php jquery ajax variables if-statement