javascript - Ajax: refresh div continuously with onclick jQuery -


i have been trying refresh div contents after button click happen 1 time , need refresh page click button again refresh content. i'm new ajax, please me solve issue.

here html:

<li id="personal-info" class="personal-info-wrapper">     <div class="profile_content" id="personal-info-contents">        **more codes follow....**       **at last**     <tr class="pro-info-set">         <td class="info-group-left">             <input class="form-control" type="text" id="js_personal_title" name="js_personal_title">         </td>         <td class="info-group form-inline">             <input class="form-control" type="text" id="js_personal_desc" name="js_personal_desc">             <input id="submit_person" class="form-control" type="button" value="add">             <label id="submit_person_msg" value="add"></label>         </td>                                            </tr>        <?php }  ?> </table> 

here js

$("#submit_person").click(function(e){     e.preventdefault();     js_personal_title = $("#js_personal_title").val();     js_personal_desc= $("#js_personal_desc").val();     if (js_personal_title !== null && js_personal_title !== "") {         if (js_personal_desc !== null && js_personal_desc !== "") {             var datastr = 'js_personal_title='+js_personal_title + '&js_personal_desc='+js_personal_desc;              $.ajax({                 type: "post",                 url: "<?php echo base_url().'index.php/jobseeker/add_personal' ?>",                 data: datastr,                 success:function(e) {                     //e.preventdefault();                     $(".personal-info-wrapper").load(location.href  + " #personal-info-contents");                 }             });         } else { alert('please enter decription');}     } else { alert('please enter title');} return false; }); 

you clearing out elements inside li element , replacing them new ones. old listeners gone. you'll have reattach listeners or use delegation. example, change this:

 $("#submit_person").click(function(e){ 

for this:

 $('.personal-info-wrapper').on('click','#submit_person', function(e) { 

this assuming .personal-info-wrapper never gets replaced.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -