开发者

jQuery form submission fail

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!


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">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜