0

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!

asked Oct 10, 2011 at 11:21
7
  • since you use "submitForm" as a "id" of form then no need to write like $('form#submitForm') just use $('#submitForm') Commented Oct 10, 2011 at 11:33
  • Pasted your code into jsFiddle here jsfiddle.net/KnWte and it's working correctly. It's definitely reaching the document.write('Hola') Commented Oct 10, 2011 at 11:34
  • The message appears in jfiddle. jsfiddle.net/yt9YY Did you include the jquery script? Did you include this file after you included jquery? Commented Oct 10, 2011 at 11:35
  • I definatly have the jQuery scripts included. Mobile jQuery and normal. I have changed it to just $('#submitForm') and that made no difference, but worth a try. Thanks again Commented Oct 10, 2011 at 11:37
  • Maybe it isn't reaching mAjax.php? Check the file path. Commented Oct 10, 2011 at 11:37

1 Answer 1

2

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">
answered Oct 11, 2011 at 6:33
Sign up to request clarification or add additional context in comments.

2 Comments

I don't think that's the problem because the form is being serialized anyways, as long as it has got an id or you are correctly pointint it to towards that form then it should be fine. Thanks anyway!
I think it was a mixture between a few things, but I used your answer as well as other things. So thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.