Bonjour,
Je suis entrain de développer mon premier plugin Jquery et j'avoue avoir bcp de mal à comprendre l'objet this, $(this), ...
J'ai un message d'erreur qui survient "Object has no method 'find'" ce qui me fait douter que pour cette méthode, mon objet this (ou $(this)) ne correspond pas.
Voici mon code :
et voici l'appel :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 (function($){ // Methodes var methods = { 'init' : function(arguments){ // Lorsque le formulaire est valide this.bind('submit', function(event){ // On empeche l'envoi event.preventDefault(); $(this).sendForm('loading', true); // On execute notre requete AJAX $.post("une url", $(this).serialize(), function(data){ for(idx in data){ var current = data[idx]; $(this).find('[name*="' + current.key + '"]').after('<span class="erreur_form">' + current.message + '</span>'); } $(this).sendForm('loading', false); }, "json"); }); return this; }, 'loading' : function(){ alert("En cours" return this; } }; // Point de lancement $.fn.sendForm = function(method){ if(methods[method]){ return methods[method].apply(this, Array.prototype.slice.call(arguments,1)); } else if(typeof method === 'object' || !method){ return methods.init.apply(this, arguments); } else { $.error('Method ' + method + ' does not exist'); } }; })(jQuery);
Merci pour vos explications,
Code : Sélectionner tout - Visualiser dans une fenêtre à part $('form').sendForm();
Nainfou
Partager