Ciao a tutti, ho una pagina che contiene un codice JS per eseguire un WS chiamando una funzione PHP
la pagina funziona perfettamente cliccando un pulsante .... mi aiutate a cambiarla per fare in modo che l'operazione venga eseguita al caricamento della pagina, senza il click del pulsante?
Grazie
codice:<h2> <?php echo $this->escape($this->title); ?> </h2> <table cellspacing="5" cellpadding="0" width="840"> <tr> <td width="180" align="center"> Carica da: <input style="width:80px;text-align:center;readonly:true;" value="2000-01-01" id="regDate" type="text" /></td> <td width="70" align="center"> <input type="checkbox" id="record" checked /> Salva </td> <td align="center" width="50"> [img]<?php echo $this->baseUrl();?>/css/images/ajax-loader.gif[/img] </td> <td width="280"><div class="divCallAuto"><button id="btnAuto" >Caricamento...</button></div> </td> </tr> </table> <div id="result"> </div> <script type="text/javascript"> $(function() { $("#regDate").datepicker({ dateFormat: 'yy-mm-dd' }, { defaultDate: +7 }); $("button, input:submit, a", ".divCallWS").button(); $("button, input:submit, a", ".divCallAuto").button(); $("button, input:submit, a", ".divCallAuto").click(function() { var running = $('#hdnServiceRunning').val(); if (running =='0'){ $('#hdnServiceRunning').val('1'); $(this).button( "option" , 'label','Stop!' ); callWs('*FIRST',false); callWs('*NEXT',true); }else{ $('#hdnServiceRunning').val('0'); $(this).button( "option" , 'label','Esegui...' ); } return false; }); function callWs(operazione, auto){ var running = $('#hdnServiceRunning').val(); if ((running == '0') && (auto)){ return false; } $("#loader").show(); url = "../ws/callws"; data = 'timestamp=' + $("#regDate").val() + '&operazione=' + operazione + '&record=' + $("#record").attr('checked') ; $.ajax({ type: "POST", url: url, data: data, dataType: "json", async: ((operazione=='*FIRST')&& (auto))?false:true, success: function(resp) { $result = '<ul>'; $result += "[*] CODICE: " + resp._CODICE + " "; $result += "[*] NOME: " + resp._NOME; + " "; $result += "[*] ... "; //and so on .... $result += '[/list]'; $("#result").html($result); $("#loader").hide(); if (resp._ESITO=='Fine'){ //we are reach the finhish $("#loader").hide(); $("#dialog-modal-send p").html ('End of Rows.'); $("#dialog-modal-send").dialog({ height: 190, modal: true}); $('#hdnServiceRunning').val('0'); $("#btnAuto").button( "option" , 'label','Run Auto...' ); return false; } //Run he service again if (auto){ callWs(operazione, true); } }, error: function(){ if (auto){ $('#hdnServiceRunning').val('0'); $("#btnAuto").button( "option" , 'label','Run Auto...' ); } $("#loader").hide(); $("#dialog-modal-send p").html ('Web Service does not responde.'); $("#dialog-modal-send").dialog({ height: 190, modal: true}); } }); } }); </script> <input type="hidden" value="0" id="hdnServiceRunning" /> <div id="dialog-modal-send" style="display:none" title="WS Response"> Web Service response ok</p> </div>

Rispondi quotando
