从下拉列表中选择后提交表单而不刷新 [英] Submit form without refresh after selection from dropdown

查看:138
本文介绍了从下拉列表中选择后提交表单而不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;
});

这篇关于从下拉列表中选择后提交表单而不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆