i've built search form , i've tried send $_post
data php in ajax not work.
and want know, possible if want send $_post
data url:"searchby.php"
in ajax?
search.php :
<form action="<?php echo htmlspecialchars($_server["php_self"]);?>" method="post" id="searchterm"> <input type="text" name="search" id="search" autocomplete="off"> <button type="loading" class="btn btn-primary">add</button> </form> <script type="text/javascript"> var ajax_arry=[]; var ajax_index =0; var sctp = 100; $(function(){ $('#loading').show(); $.ajax({ url:"searchby.php", type:"post", data:"actionfunction=showdata&page=1", cache: false, success: function(response){ $('#loading').hide(); $('#demoajax').html(response); } }); $(window).scroll(function(){ var height = $('#demoajax').height(); var scroll_top = $(this).scrolltop(); if(ajax_arry.length>0){ $('#loading').hide(); for(var i=0;i<ajax_arry.length;i++){ ajax_arry[i].abort(); } } var page = $('#demoajax').find('.nextpage').val(); var isload = $('#demoajax').find('.isload').val(); var searchterm = "<?php echo $x; ?>"; if ((($(window).scrolltop()+document.body.clientheight)==$(window).height()) && isload=='true'){ $('#loading').show(); var ajaxreq = $.ajax({ url:"searchby.php", type:"post", data:"actionfunction=showdata&page="+page, cache: false, success: function(response){ $('#demoajax').find('.nextpage').remove(); $('#demoajax').find('.isload').remove(); $('#loading').hide(); $('#demoajax').append(response); } }); ajax_arry[ajax_index++]= ajaxreq; } return false; if($(window).scrolltop() == $(window).height()) { alert("bottom!"); } }); }); </script>
and searchby.php
should this.
searchby.php :
$searchstring = $_post['search']; $sql = "select * product p_name '%$searchstring %'";
you need send search value in ajax param as:
var searchval = $("#search").val(); // value of search box $.ajax({ url:"searchby.php", type:"post", data:"search="+searchval+"&actionfunction=showdata&page=1", cache: false, success: function(response){ $('#loading').hide(); $('#demoajax').html(response); } });
update 1:
send ajax request when form submit, can follow example:
$(".btn").click(function(){ var searchval = $("#search").val(); // value of search box $.ajax({ url:"searchby.php", type:"post", data:"search="+searchval+"&actionfunction=showdata&page=1", cache: false, success: function(response){ $('#loading').hide(); $('#demoajax').html(response); } }); });
in php (searchby.php) debug getting in $_post:
echo "<pre>"; print_r($_post);
Comments
Post a Comment