javascript - Single DIV refreshed - e.preventDefault(); -
when user search items in <div class="searchbar">
want post
data <div id="auto">
, <div id="auto">
refreshed rather reloading full page.
my problem when submit button clicked, entire page loading. need able refresh <div id="auto">
when submit button clicked. main purpose want avoid <div class="menulist">
being reloaded every time submit clicked. below code.
<div class="searchbar"> <form action="" method="post"> furniture item: <input type="text" name="val1" id="val1" value="<?=$_post['val1']?>" /> <input type="submit" id="submit" value="submit" name="submit" /> </form> </div> <div class="menulist"> list of furniture: <select id='mylist' name="mlist" onchange='document.getelementbyid("val1").value = this.value;'><option value="">furniture available</option> </select> </div> <div id="result"></div> <script type="text/javascript"> $(document).ready(function() { refresh(); }); function refresh(){ $("#submit").click(function(e) { e.preventdefault(); $.ajax({ url: 'php/filep.php', type: 'post', data: $('#submit').val, success: function(data, status) { $("#result").html(data) } }); $(".result").fadeout("slow"); refresh(); }); } </script> </body>
filep.php
if( isset($_post['submit']) ){ $resdata = htmlentities('img/'.$_post['val1']).'/'; } if( isset($resdata) ) { $files = '*.*'; $fin = glob($resdata.$files); $counts = count($fin); $imgs = array(); $div= ''; foreach ($imgs $fin) { $div .= '<div class="imgslots">'; $div .= '<li><div class="imgslotsinner"><input type="image" src="'.$fin.'"/><testdes>"'.basename($fin.$files).'"</testdes></div></li>'; $div .= '</div>'; } echo $div; }
yes can refresh single div only. need refresh html of div i.e. first delete html of div
$('#auto').html('');
and put content again have fetched ajax posting in div. if going refresh grid or table write inline html , fill data coming ajaxpost. may use .each method make in loop
thanks
Comments
Post a Comment