从下拉列表中选择后提交表单而不刷新

问题描述:

我正在尝试设置一个表单,以便从下拉菜单中进行选择时提交(不刷新页面).我目前已将其设置为在选择下拉列表时提交,但它会刷新页面.

I'm trying to set up a form so that it submits (without refreshing the page) when a selection is made from a dropdown menu. I currently have it set to submit when the dropdown is select, but it refreshes the page.

我的表单代码是

<form action="" method="get">
<select name="day" onchange="this.form.submit();">
<option>Please select a date</option>
<option value="Mon"><?php echo $monday; ?></option>
<option value="Tue"><?php echo $tuesday; ?></option>
<option value="Wed"><?php echo $wednesday; ?></option>
<option value="Thu"><?php echo $thursday; ?></option>
<option value="Fri"><?php echo $friday; ?></option>
</select>
</form>

我已经尝试了一些关于jQuery表单的jQuery教程,而没有刷新,但是它们都包含一个Submit按钮.当下拉菜单中选择一个选项时,我需要一个将表单提交与之绑定的对象.

I've tried several jquery tutorials on submitting forms without a refresh, but they all involve a submit button. I need one that binds the submitting of the form to when a choice is selected in the dropdown.

任何帮助将不胜感激.

已解决 使用此处的答案中的一些想法,一些教程以及大量的尝试/错误.我终于弄明白了.这是有效的代码

Solved Using some of the ideas from the answers here, some tutorials, and a lot of trial/error. I finally got it figure out. Here is the code that works

$('#day').change(function() 
{
   $.ajax({
        type: 'post',
        url: "tutoringlistsession.php",
        data: $("form.day").serialize(),
        success: function() {
            $('#list').load('tutoringlist.php', function(){
            });
            $('#list').show("fast");
        }
    });
                return false;
});

我使用了此处发布的想法以及一些教程来找出答案.工作代码如下:

I used the ideas posted in here and several tutorials to figure out the answer. The working code is below:

$('#day').change(function() 
{
   $.ajax({
        type: 'post',
        url: "tutoringlistsession.php",
        data: $("form.day").serialize(),
        success: function() {
            $('#list').load('tutoringlist.php', function(){
            });
            $('#list').show("fast");
        }
    });
                return false;
});