在使用ajax检索文本框中的值类型时出现问题


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>

这里我得到输入框htl_name的值,但整个页面重新加载。如何解决这个问题?

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 this doesn't work, replace it with "return false"
    });
    });