views:

91

answers:

1

I've been developing / testing a site locally on a MAMP (e.g. LAMP) environment. I have a form that's processed by jQuery that works fine locally; I don't want it to be submitted, but to send the values to an AJAX function.

The issue is that it submits to the 'action' destination of the form parameter when it's run on a remote server with pretty much the same set up, e.g. Apache, PHP, etc. None of the code is different. So when I submit the form, the jQuery doesn't catch the form, it just goes ahead and submits.

Any ideas? Thanks in advance.

jQuery:

function save_words_ajax(username, save_word, save_meaning) {
 $.ajax({
  type: "GET",
  url: "ajax/save_word.ajax.php",
  data: "username=" + username + "&save_word=" + save_word + "&save_meaning=" + save_meaning,
  dataType: "html",
  success: function(html){
   $("#complete h2").html(html);
   $("#complete").show("fast");
  },        
  complete: function(){
  setTimeout('$("#complete").hide("fast")', 1500);
  }
 });
}

html:

<form id="new_word_form" action="ajax/save_word.ajax.php" method="get" accept-charset="utf-8">
 <p>                
   <input type="hidden" name="username" value="someusername" />
   <input type="hidden" name="word_reset" value="word" />
   <input type="text" name="save_word" value="word" class="clearme" />

   <input type="hidden" name="meaning_reset" value="meaning" />
   <input type="text" name="save_meaning" value="meaning" class="clearme" />

   <input type="submit" name="some_name" value="+" id="some_name" />
 </p>
</form>
+4  A: 

Make sure jQuery and your capturing code is available on the site, e.g. ensure it is loaded by inspecting the source with Firebug.

Also make sure the event listener to capture the form submission is correctly registered and the event is terminated. The code you posted does not show where and how the onSubmit event is handled.

Gordon