View Single Post
Old 03-14-2013, 08:26 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,260
Thanks: 10
Thanked 532 Times in 526 Posts
devnull69 will become famous soon enough
It should not be our task to format your code. It is a general and important task for a developer who wants (and must) debug his/her own code.

Code:
$(document).ready(function() {
   $('#formId').submit(function() {
      $.ajax({
         type: 'POST',
         url: 'http://www.eshop-bazar.com/market/',
         data: '$('#formId').serialize()',
         success: 'function(data, textStatus, jqXHR) {
            '{e.preventDefault();
            alert('Added to Your cart, please continue');
         },
         error: function(jqXHR, textStatus, errorThrown) {
         }
      });
      return false;
   });
});
What do we see now?
- Single quotes inside single quotes must be escaped as \'. But you must not have single quotes around Javascript statements. Otherwise they won't be statements any more
- There is an extra single quote before the function keyword in the success method
- There is an extra single quote and opening bracket inside the success method (before e.preventDefault())
- It doesn't make any sense to have e.preventDefault inside the success method. At that point of time the .submit() handler already finished

Try this
Code:
$(document).ready(function() {
   $('#formId').submit(function(e) {
      $.ajax({
         type: 'POST',
         url: 'http://www.eshop-bazar.com/market/',
         data: $("#formId").serialize(),
         success: function(data, textStatus, jqXHR) {
            alert('Added to Your cart, please continue');
         },
         error: function(jqXHR, textStatus, errorThrown) {
         }
      });
      e.preventDefault();
      return false;
   });
});
devnull69 is offline   Reply With Quote