Ciao a tutti, ho una pagina PHP (+Zend) che esegue un'operazione al click di un pulsante; io vorrei modificarla per fare in modo che venga esetuita automaticamente all'apertura della pagina e non al click, ma non so come fare
questa è la vista Zend
codice:
<table cellspacing="5" cellpadding="0" width="840">
<tr>
<td width="180" align="center"> Data <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" >Auto...</button></div> </td>
<td width="160"><div class="divCallWS"><button>First</button></div></td>
<td width="230"><div class="divCallWSNext"><button id="btnNext" >Next>></button></div></td>
</tr>
</table>
<script type="text/javascript">
$(function() {
$("#regDate").datepicker({ dateFormat: 'yy-mm-dd' }, { defaultDate: +7 });
$("button, input:submit, a", ".divCallWS").button();
$("button, input:submit, a", ".divCallWSNext").button();
$("button, input:submit, a", ".divCallAuto").button();
$("button, input:submit, a", ".divCallWS").click(function() {
callWs('*FIRST',false);
return false;
});
$("button, input:submit, a", ".divCallWSNext").click(function() {
callWs('*NEXT',false);
return false;
});
$("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','automatic' );
}
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 += "[*] aaaa: " + resp._aaaa + " ";
$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" />
questa è l'action che viene eseguita
codice:
public function callwsAction() {
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost();
try {
$timestamp = isset($data['timestamp']) ? $data['timestamp'] : '';
$operazione = isset($data['operazione']) ? $data['operazione'] : '';
$record = isset($data['record']) ? $data['record'] : '';
if (isset($timestamp)) {
$timestamp = $timestamp . '-00.00.00.000000';
};
$result = $this->_callWs($timestamp, $operazione);
...
Come posso fare in modo che all'apertura della pagina venga eseguita l'operazione che solitamente esegue il pulsante "btnAuto" .... ovviamente posso cancellare ogni riferimento alle azioni svolte dagli altri due pulsanti btnNext e First
Grazie a tutti!!