php - Refresh div using ajax -
i need refresh select (by id) when ajax call successful. have no idea how process
ajax function :
$('#insertform').on('click', function(){ var form_intitule = $('input[name=form_intitule]').val(); $.ajax({ type: "get", url: "lib/function.php?insertform="+insertform+"&form_intitule="+form_intitule, datatype : "html", error: function(xmlhttprequest, textstatus, errorthrown) { alert(xmlhttprequest + '--' + textstatus + '--' + errorthrown); }, success:function(data){ /*here need reload #listeformation*/ } }); });
html.php
<div class="form-group"> <label for="nomsalarie" class="col-sm-1 control-label" id="nameselect">formations</label> <div class="col-sm-11"> <select name="listeformation[]" id="listeformation" class="form-control" multiple>'; while($ligne = $displayformation->fetch()){ $data['formation'] .='<option value="'. $ligne['form_id'].'">'.$ligne['form_intitule']. " [" . $ligne['form_organisme'] . "]".'</option>'; } </select> </div> </div>
there 2 ways in thought:
- use $.load() jquery like: (it's inject response node select)
$('#insertform').on('click', function(){ var form_intitule = $('input[name=form_intitule]').val(); $("#listeformation").load( "lib/function.php", { insertform: insertform, form_intitule: form_intitule }, function(response, status, xhr){ if(status == "error"){ alert(xhr + '--' + xhr.status + " " + xhr.statustext); }else{ // process html want here.. lets call: 'html_you_want_to_inject' $('#listeformation').html(html_you_want_to_inject); } } }); });
- using code, use simplely:
$("#listeformation").html(html_you_want_to_inject);
i guess 1 point think remove php div , turn div dinamic since page load javascript. kill php each time ajax runs, rewriting content in runtime.
Comments
Post a Comment