我有以下职能。 一个人应当收到一张假药,然后通过美国宇宙航空研究开发机构转交该笔药。
Yet, while I know the "initiateSubCategories" function is working, for whatever reason the ajax function refuses to work. It s supposed to send the data to the very same file it s called in, and I have a feeling that this may be the issue.
这里是否有任何人错了? 我曾尝试通过对我的贾瓦文进行论证,但所有给我的人都对我的代码格式(这里不是问题,而是在我确定之后)提出了一些特尼特的悲tty抱怨。
我的守则如下:
function sendAjaxDataViaPost(pathToFile, ajaxData) {
$.post(pathToFile, function(ajaxData) {
alert("Data loaded: " + ajaxData);
$( #pageOne ).append( <pre> + ajaxData </pre> );
});
}
function initiateSubCategories(parent) {
//$("#pageOne").append("<pre>" + parent + "</pre>");
sendAjaxDataViaPost( form.php , parent);
<?php
$categories = $this->formData->getCategories($_POST[ value ]);
?>
printSubCategories(<?=$categories;?>);
}
因此,我错了吗? 我在Embeth和Kinor试图这样做,也未能生产任何东西。
<>Update>
我改变了职能,使用了以下格式:
$.post(pathToFile, { id: ajaxData }, function(ajaxData) {
alert("Data loaded: " + ajaxData);
$( #pageOne ).append( <pre> + ajaxData </pre> );
});
然而,当我试图提出<代码>_POST[id]时,它告诉我它没有提及。
???
<><>Update 2
I just found in FireBug s console that my "initiateSubCategories" function is undefined. What I d like to know is how this is possible...
我把我的整个法典放在后面——第二层眼睛可能确实有助于这一条。
<?php
$target = JPATH_BASE.DS."index.php?action=com_adsmanager&task=save&Itemid=".$this->itemId;
$saveTarget = JPATH_BASE.DS."index.php?action=com_adsmanager&task=Itemid=".$this->itemId;
function populateCategories($parent, FormData $formData) {
$categories = $formData->getCategories($parent);
foreach($categories as $section => $row){
?>
<option value=<?=$row[ id ];
?>>
<?php
echo $row[ name ];
?>
</option>
<?php
}
}
?>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js">
</script>
<script type="text/javascript">
function sendAjaxDataViaPost(pathToFile, ajaxData) {
$.post(pathToFile, { id : ajaxData}, function(ajaxData) {
alert("Data loaded: " + ajaxData);
$( #pageOne ).append( <pre> + ajaxData </pre> );
});
}
function initiateSubCategories(parent) {
sendAjaxDataViaPost( form.php , parent);
$("#pageOne").apppend( <pre> + <?=$_POST;?> + </pre> ));
}
function printSubCategories(categories) {
for (var i = 0; i < categories.length; i++) {
var opt = document.createElement("option");
opt.text = categories[ name ];
opt.value = categories[ id ];
$("#subcategories").append(opt);
}
}
</script>
<div id="pageOne">
<form action=<?=$saveTarget;?> method="post" enctype="multipart/form-data">
<select name="category" id="categories" class="ads_categories" onclick="initiateSubCategories(this.value);">
<option value="0">--Please choose a category--</option>
<?php populateCategories(0, $this->formData); ?>
</select>
<select name="category" id="subcategories" class="ads_subcategories">
<option value="0">--Please choose a subcategory--</option>
</select>
</form>
</div>