javascript - Show succes message from ajax -
i have question, create sistem update in database row when onchange select box. goes well, want drop succes message if update succes.
my view :
<form action="" id="updatestatus" method="post"> <select id="statusselect" name="{{ gift.id_instant_gagnant }}" class="form-control" onchange="updatecadeaustatus({{ gift.id_instant_gagnant }})"> {% key,statut in form_logistique.statut.choices %} <option value="{{ key }}" {% if gift.etat == key %}selected="selected"{% endif %}> {{ statut }} </option> {% endfor %} </select> </form> <script> function updatecadeaustatus(id) { var id = id; var selectedname = $("#statusselect option:selected").val(); var url_deploy = 'http:localhost/updatestatus' console.log(id); console.log(selectedname); $.ajax({ url: url_deploy, type: "post", async: true, data: { id_cadeau:id, id_status:selectedname} }); } </script>
the controller :
public function updatestatus(){ $igiftid = $_post['id_cadeau']; $inewstatus = $_post['id_status']; $bupdate = $this->updatestatusbygiftid($igiftid, $inewstatus); return $this->render('logistique.twig'); }
the model :
public static function updatestatusbygiftid($igiftid, $istatusid){ $request = sprintf( ' update `%s` set etat = %d id = %d ', $table, $istatusid, $igiftid); return mysqli::query($request, $database); }
so goes want drop message after every update, displayed in view. please me!!! thx in advance, sorry english.
$.ajax({ url: url_deploy, type: "post", async: true, data: { id_cadeau:id, id_status:selectedname}, success : function(data){ console.log('success'); }, error: function(){ console.log('error'); } });
Comments
Post a Comment