php - ajax value pass but no output -
i using textarea. user type one/more letter presses tab. ajax called display select box based on textarea input.
<body> <textarea id='test' name="test"></textarea> <div id="selectbox"></div> <script type="text/javascript"> document.getelementbyid('test').onkeydown = function(e){ if (e.keycode == 9) { this.value += " "; if(e.preventdefault) { var search = document.getelementsbyname('test')[0].value; e.preventdefault(); $.ajax({ type: "post", url: "nishaone.php", data: "search=" +search, success: function(msg){ $(document).ajaxcomplete(function (event, request, settings){ $("#selectbox").html(msg); }); } }); } return false; } } </script> </body>
i check ajax coding. values passed. looks fine. here php file using.
if (isset($_post['search'])&& $_post['search']){ echo $_post['search']; echo '<select name="plid" id="plid">'; echo '<option value="" selected="selected">--select pack name--</option>'; $tempholder = array(); $query = "select acname glmast acname '". mysql_real_escape_string($_post['search']) ."%' order acname "; $done=mysql_query($query) or die(mysql_error()); $nr = mysql_num_rows($done); ($i=0; $i<$nr; $i++){ $r = mysql_fetch_array($done); if (!in_array($r['acname'], $tempholder)){ $tempholder[$i] = $r['acname']; echo "<option value='$r[acname]'>".$r["acname"]."</option>"; } } }
so sql query output.
i tried without if condition. works great.
the post values passes. output blank select box no values in it.
any idea?? highly appreciated! thanks..
i created jsfiddle example page side
http://jsfiddle.net/utku/cvelh/3/
can change ajax query this
$.ajax({ type: "post", url: "nishaone.php", data: {search: search}, success: function (msg) { // assume "<option>something</option>" output server $("#selectbox").append(msg); } });
Comments
Post a Comment