Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Не пойму, где 'undefined' (ajaxForm, simpleCart) (https://javascript.ru/forum/jquery/34360-ne-pojjmu-gde-%27undefined%27-ajaxform-simplecart.html)

adelante 31.12.2012 02:35

Не пойму, где 'undefined' (ajaxForm, simpleCart)
 
$(document).ready(function(){

simpleCart({ /*options for simpleCart */ });

$('#order').ajaxForm({ 
		    
			beforeSubmit: function(arr,$form, options){
				if ( !validateEmail( $('#email').attr('value') ) ) {
					alert('Only valid email address is allowed to be entered into the "email" field');
					return false;
				} else {
					return  null ;
				}
			},
			success: function(data){    								
				simpleCart.each(function( item , x ){
				    item.remove();
				});
				
				$('#descr').html(data);	
			}
			
		}); 

function validateEmail(email) { 
	   if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))  
	    {  
	      return true;  
	    }  
	      return false;
	}

});


Выдаёт ошибку "Type error: 'undefined' is not a function (evaluating'$('#order').ajaxForm')"

Hoshinokoe 31.12.2012 03:24

adelante,

Как я понимаю, используете этот плагин. Ошибка говорит о том, что плагин не подключен, но вы пытаетесь его использовать. Проверьте, правильно ли вы его подключили:

<html> 
<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
    <script src="http://malsup.github.com/jquery.form.js"></script> 
 
    <script> 
        // wait for the DOM to be loaded 
        $(document).ready(function() { 
            // bind 'myForm' and provide a simple callback function 
            $('#myForm').ajaxForm(function() { 
                alert("Thank you for your comment!"); 
            }); 
        }); 
    </script> 
</head>

adelante 31.12.2012 03:34

Я почему-то считал, что он уже сразу в jQuery есть. Теперь ошибка пропала, спасибо.


Часовой пояс GMT +3, время: 04:43.