php - issue in retrieving value type in text box using ajax -
<script> $(function(){ $("input[name='room_type']").focus(function () { var str = ""; $("select[name='htl_name'] option:selected").each(function () { str += $(this).text() + " "; }); jquery.ajax({ type: "post", url:"", data: $("form#insertform").serialize(), success: function(data){ jquery(".res").html(data); $('#test').html(data); } }); var str = $("form").serialize(); $(".res").text(str); }); }); </script> here i'm getting value typed in input box htl_name whole page reloading. how solve issue?
try this:
$(function(){ $("input[name='room_type']").focus(function (e) { var str = ""; $("select[name='htl_name'] option:selected").each(function () { str += $(this).text() + " "; }); jquery.ajax({ type: "post", url:"", data: $("form#insertform").serialize(), success: function(data){ jquery(".res").html(data); $('#test').html(data); } }); var str = $("form").serialize(); $(".res").text(str); e.preventdefault(); //if doesn't work, replace "return false" }); });
Comments
Post a Comment