Hi all:
Here is a problem when using the customer ajax in cake.
The requirement is that:
I want to implement upload without refreshing the whole page
so I add target attribute for form(using iframe)
=>target="uploadframe">
and  hold all the datas in the form to action=>"../umanager/save/<?php
echo $detail['id']?>";
in the comtroller here is the function save:
function save($id){
                $this->layout = 'ajax';
                if (!empty($this->params['form'])){
                        
move_uploaded_file($this->params['form']['file']['tmp_name'],"c:/temp/".$this->params['form']['picAdd1ChildName1']['name']);

                }else{
                        $this->log("all data is: no data set", LOG_DEBUG);
                }

                $this->set('aimId',$id);
                $this->set('upload_msg',"Good!");
                $this->set('updatedArea',"aimdetail".$id);
}


and in the save.thtml I wrote the ajax codes which link to another
function in the
controller to get the detail about this saved item and show it after
saving.

save.thtml:
 <script type="text/javascript">
        var xmlHttp;
        var datas;
        var aimId;
        function createXMLHttpRequest() {
            if (window.ActiveXObject) {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if (window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();
            }
        }

        function getData() {
            createXMLHttpRequest();
            aimId="<?php echo $aimId?>";
            var url = "umanager/getAimDetail/"+aimId;//here is the
action to get and show

            xmlHttp.open("GET", url, true);
            xmlHttp.onreadystatechange = callback;
            xmlHttp.send(null);
        }

        function callback() {
            if (xmlHttp.readyState == 4) {
                if (xmlHttp.status == 200) {
                   datas=xmlHttp.responseText;
                }
            }else{
                datas="loading...";
            }

            var updatedArea="<?php echo $updatedArea?>";
            parent.document.getElementById(updatedArea).innerHTML =datas;
            parent.document.getElementById("message").style.display = "block";
            parent.document.getElementById("message").innerHTML = "<?php echo
$upload_msg ?>";

setTimeout("parent.document.getElementById('message').style.display =
'none'", 3000);


        }

        getData();
</script>


The problem is that:

when I click the save button,I found that the function in the
save.thtml does'nt work
that is function "umanager/getAimDetail/"+aimId is not called and
instead, the function
"save" is called twice.I wonder why?one is when clicking the "save"
button.and I do not known
the second time when it is called.
Thanks all!


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to