jQuery execute php script on button click and analyse results? -


task: when button clicked - disables button, executes php script. based on value php script returns - want perform 1 of 2 actions!

1) if php returns "ok", reload current page;

2) if php returns "notok:notoktext", fill #updateresult div notoktext, reenable button.

<button id="updatebutton" onclick="update_btn_click('params');">execute php</button> 

and here's jquery have far. near doing want. loads div output of php , doesn't wait while loading finishes (php try fetch data server, take time) - re-enables button.

function update_btn_click(param) {  $('#updatebutton').prop("disabled",true); $('#updatebutton').text("processing...");   $("#updateresult").load("/update.php");  //how wait result , analyse has been returned?  //act upon result     $('#updatebutton').removeattr('disabled');} 

function update_btn_click(param) {     $('#updatebutton').prop("disabled",true);     $.ajax({         url:"update.php",         type:"post",         success: function(response){             if(response=='ok') {                 location.reload();             } else {                 $("#updateresult").html('error');                 $('#updatebutton').prop("disabled",false);             }         },         error: function(response){             console.log('could not fetch data');         },         complete: function(response){             // hide loading         }     }); } 

in update.php

if(action) {     echo 'ok'; } else {     echo 'error'; } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -