Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > JavaScript > Bibliothèques & Frameworks > jQuery
jQuery Forum d'entraide sur le framework jQuery. Avant de poster : Tutoriels jQuery, FAQ jQuery, Tous les tutoriels JavaScript, Toutes les FAQ JavaScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 15/07/2011, 11h49   #1
Candidat au titre de Membre du Club
 
Inscription : mai 2010
Messages : 80
Détails du profil
Informations forums :
Inscription : mai 2010
Messages : 80
Points : 10
Points : 10
Envoyer un message via MSN à doud180878
Par défaut Récupérer des données en AJAX

Bonjour,

Comme dit dans l'intitulé, j'ai un petit soucis pour récupérer des données.

J'ai un fichier emails.liste.html ou j'ai mon formulaire et mes données en jquery et un autre fichier ou je transmet les données pour qu'elles soient traités : emails.php :

emails.liste.html :
Code :
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 520,
			width: 400,
			modal: true,
			buttons: {
				"Créer un compte": function() {
					/*var bValid = true;
					allFields.removeClass( "ui-state-error" );
 
					bValid = bValid && checkLength( nom, "nom", 2, 20 );
					bValid = bValid && checkLength( prenom, "prenom", 2, 20 );
					bValid = bValid && checkLength( adresse, "adresse", 5, 40 );
                    bValid = bValid && checkLength( code_postal, "code_postal", 3, 16 );
					bValid = bValid && checkLength( ville, "ville", 5, 16 );
					bValid = bValid && checkLength( telephone, "telephone", 5, 16 );
					bValid = bValid && checkLength( email, "email", 6, 80 );
 
 
					bValid = bValid && checkRegexp( nom, /^[a-z]([0-9a-z_])+$/i, "Le nom of a-z, 0-9, underscores, begin with a letter." );
					bValid = bValid && checkRegexp( prenom, /^[a-z]([0-9a-z_])+$/i, "Le prenom may consist of a-z, 0-9, underscores, begin with a letter." );
					bValid = bValid && checkRegexp( adresse, /^[a-z]([0-9a-z_])+$/i, "l'adresse may consist of a-z, 0-9, underscores, begin with a letter." );
					bValid = bValid && checkRegexp( code_postal, /^([0-9])+$/, "Le mote de passe field only allow : 0-9" );
					bValid = bValid && checkRegexp( ville, /^[a-z]([0-9a-z_])+$/i, "La ville may consist of a-z, 0-9, underscores, begin with a letter." );
					bValid = bValid && checkRegexp( telephone, /^([0-9])+$/, "Le telephone field only allow : 0-9" );
					bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. ui@jquery.com" );
					*/
				/*	if ( bValid )
					{*/
 
						$( "#users" ).append( "<tr>" +
							"<td>" + nom.val() + "</td>" +
							"<td>" + prenom.val() + "</td>" +
							"<td>" + code_postal.val() + "</td>" +
							"<td>" + ville.val() + "</td>" +
							"<td>" + telephone.val() + "</td>" +
							"<td>" + email.val() + "</td>" +
							"<td>" + groupe.val() + "</td>" +
						"</tr>" );
 
 
 
					//var data = $("#dialog-form > form" ).serialize();
					//alert (data);
					$.ajax({
					 type: "POST",
					 url: "/modules/emails.php",
					 data: $("#dialog-form form" ).serialize(),
					 success: function(msg){
					     alert( "Data Saved: " + msg );
					     info_good("Le nouveau contact a bien été crée");
					   }
 
 
					});
 
								$( this ).dialog( "close" );
 
 
 
				/*	}*/
 
 
 
 
											},
					Annuler: function()
					 {
							$( this ).dialog( "close" );
					 }
 
 
 
					},

emails.php:


Code :
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
	print_r($_POST);
	 //echo $_POST['prenom'];
 
		// ajout d'un enregistrement
	if(!empty($_POST['nom']) AND !empty($_POST['prenom']))
	{
		echo $_POST['prenom'];
		// sécurisation
		$nom = addslashes(strip_tags(trim($_POST['nom'])));
		$prenom = addslashes(strip_tags(trim($_POST['prenom'])));
		$adresse = addslashes(strip_tags(trim($_POST['adresse'])));
		$code_postal = $_POST['code_postal'];
		$ville = addslashes(strip_tags(trim($_POST['ville'])));
		$pays = addslashes(strip_tags(trim($_POST['pays'])));
		$telephone = $_POST['telephone'];
		$email = addslashes(strip_tags(trim($_POST['email'])));
		$abonne = 1;
		$groupe = (int)$_POST['groupe'];
 
 
 
		// enregistrement
		$sql = "INSERT INTO emails ( nom, prenom, adresse, code_postal, ville, pays, telephone, email, abonne, groupes_id )
				VALUES ('$nom', '$prenom', '$adresse', '$code_postal', '$ville', '$pays', '$telephone', '$email', '$abonne', '$groupe');";
 
				echo $sql;
				exit;
 
			if($db->query($sql))
			{
				$tpl->assign_block_vars('msgbox', array(
					'icone' => 'info',
					'msg' 	=> "L'email a été ajouté."
			));
 
	 		}
			else
			{
				$tpl->assign_block_vars('msgbox', array(
					'icone' => 'error',
					'msg' 	=> "Une erreur est survenue."
			));
			}
 	}
Alors quand je valide mon formulire j'ai bien les données passées en post mais je n'ai aucune insertion ?? Bizarre.

Quand je passe par un serialize et que je n'ai pas une fonction de retour por insérer les données dans ma base.

Merci
doud180878 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/07/2011, 13h03   #2
Membre éclairé
 
Homme
F5(){F5}
Inscription : avril 2008
Messages : 256
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Rhône (Rhône Alpes)

Informations professionnelles :
Activité : F5(){F5}
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : avril 2008
Messages : 256
Points : 320
Points : 320
salut,

tu peux faire une requete GET à la place de POST (type:'get').
Comme ca, ca te permet de voir l'url qui est générée, et de fait tu peux déjà tester le retour du serveur par l'url, sans te soucier du javascript, cad : est-ce que le serveur fait tout ce qu'il faut.

Tu peux également looker de ce côté :
Code :
1
2
3
4
5
6
,success:function(){
 //classic stuff
},
error:function(){
 //voir api jQuery
}
voir si le serveur retourne bien avec un header ok, sinon, tu peux chopper le retour dans le callback de error
galerien69 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 22h03.


 
 
 
 
Partenaires

Hébergement Web