English 中文(简体)
Sending AJAX calls to the same php file
原标题:Sending AJAX call to the same php file

我有以下职能。 一个人应当收到一张假药,然后通过美国宇宙航空研究开发机构转交该笔药。

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>
最佳回答

改变你的职位要求

$.post(pathToFile, {  id : ajaxData }, function(ajaxData) {
    alert("Data loaded: " + ajaxData);
    $( #pageOne ).append( <pre>  + ajaxData  </pre> );
});

我假定,在你打电话之前,你通过阿加克斯·达塔寄出一些价值。

function sendAjaxDataViaPost(pathToFile, ajaxData) { 
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签