【发布时间】:2014-04-23 07:06:35
【问题描述】:
您好,所以我的总体目标是单击一个表获取其 ID,然后使用其 ID 加载另一个表。到目前为止,我能够获取 ID,但是当我尝试加载第二个表时,我得到了错误
"未定义索引:C:\xampp\htdocs\abac\ajaxupdate.php 中的 Projec_ID 第 6 行“
这是我的代码
AJAX 脚本(控制台打印 rowID 以便获取,我认为尝试传递时出现问题的变量?)
<script language="javascript" type="text/javascript">
$(document).ready(function() {
var log = $("#log");
$(".getRow").click(function() {
console.log("Clicked a row...");
rowID = $(this).find("td.idCell").text();
//Print the row ID in the log cell to make sure we got the right one.
log.text("You 1clicked row "+rowID);
console.log("You cl2icked row "+rowID);
//Send the row ID to ajaxupdate.php
$.post("/abac/ajaxupdate.php", { what: "updateRow", Projec_ID: rowID})
.done( function(data) {
var results = $.parseJSON(data);
console.log(rowID );
})
.fail( function() {
console.log("AJAX POST failed.");
});
});
});
</script>
PHP 文件 (ajaxupdate.php) 我认为这里有问题我猜
<?php
if( (isset($_POST['submit'])) || (isset($_POST['Projec_ID'])) )
{
$Projec_ID =($_POST['Projec_ID']);
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName(array('CV_ID', 'Classifier', 'Value', 'TP_ID')))
->from($db->quoteName('sessionta'))
//also is the like part right?
->where($db->quoteName('TP_ID') . ' LIKE '. $db->quote($_POST['Projec_ID']));
$db->setQuery($query);
$results = $db->loadObjectList();
//echo $Classifier;
}
?>
【问题讨论】:
-
您的表单设置为使用 POST 还是 GET?
-
你试过了吗,$Projec_ID =$_POST['Projec_ID'];
-
检查您的 AJAX 请求标头并确保将 Projec_ID 传递给服务器。我使用谷歌开发工具来检查这一点。还有为什么你分配
$Projec_ID = $_POST['Projec_ID'],却从不使用它。 -
查看您的 JQuery 后,我认为将
rowID = $(this).find("td.idCell").text();更改为var rowID = $(this).find("td.idCell").text();这是因为rowId不在$.post()JQuery 函数调用的范围内。并且可以解决您的问题。 -
不,在这种情况下你需要 POST
标签: php jquery mysql ajax post