csdn产品小助手 2011-10-10 11:21 采纳率: 0%
浏览 20

jQuery表单提交失败

Good Afternoon everybody.

I have got a quick question to ask about why my jQuery is not submitting my form data.

This is my form:

 <form id="submitForm" action="" method="">
                <input class="ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c" type="text" name="from" placeholder="Your Email" style="color:#ccc;" />
                <input class="ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c" type="text" name="fullName" placeholder="Your Full Name" style="color:#ccc;"  />
                <input class="ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c" type="text" name="contactNumber" placeholder="Your Contact Number" style="color:#ccc;"  />
                <input class="ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c" type="text" name="subject" placeholder="Subject" style="color:#ccc;"  />
                <textarea placeholder="Your Message Here..." class="ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c" name="body" style="color:#ccc;" ></textarea>

                <input type="submit" id="search_button" value="Submit!" name="submit" />

            </form>

Here is my jQuery code:

 <script type="text/javascript">
        $(document).ready(function(){

            $('#loading, .loading-text').hide();

            $('form#submitForm').submit(function( event ){

                event.preventDefault();

                document.write('Hola!');

                $('#loading').show();
                var formData = $('form#submitForm').serialize();
                $.ajax({
                    url: 'mAjax.php',
                    data: formData,
                    type: "get",
                    success: function( data ){
                        $('#loading, .loading-text').show();

                        if( !data.error ){
                            $('.alertText').html(data).show();
                        } else {
                            $('.alertText').html(data + data).show();
                        }
                        $('#loading, .loading-text').hide();
                    }
                });
                return false;
            });
        });
    </script>

I know this may be a vague question, but I have been trying for a while now and I can't think of anything else to try.

The problem that I'm having is that when I click submit or just submit the form, nothing happens, it doens't reach the document.write('Hola!'); bit and it most definatly doesn't reach the AJAX call.

Any help on what I could try to help this would be much appreciated.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • 妄徒之命 2011-10-11 06:33
    关注

    I think this is because you didn't provide a method and an action.
    Instead of:

    <form id="submitForm" action="" method="">
    

    Do:

    <form id="submitForm" action="[your current file]" method="GET">
    
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建