Bonjour
Je travaille sur un projet de gestion de flottes en ASP .net. Je suis en train de développer une interface de login en jquery mobile et je dois utiliser un web service asp.net (.asmx) et ajax JSON pour le transfert des données.
voilà mon code jquery
fichier login.htm
et voilà le cose de mon web service
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 <!DOCTYPE html > <html> <head> <title>Login</title> <meta name="viewport" content="width=device width,initial-scale=1"/> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.min.css" /> <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> <script src="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.min.js"></script> <script type="text/javascript"> $.document.ready(function () { }); function callservice(){ $.Ajax({ type:"Post", contentType: "application/json; charset=utf-8", url: "../authentification.asmx/Authentifier", //data:"{email:"+$('#email').val()+", password:"+$('#password').val()+"}", data:"{}", datatype:"JSON", Success:OnSuccessCall(), erreur:OnErreurCall() }); } function OnSuccessCall(response) { $("#divResponse").text(response.d); } function OnErreurCall(response) { $("#divResponse").text(response.status+" "+response.statustext); } </script> </head> <body> <div data-role="page" id="login" data-theme="b"> <div data-role="header"> <h1>Login</h1> </div> <!-- start content --> <div data-role="content" data-inset="true"> <form name="loginform" id="formulaire" > <fieldset > <label for="email">Email:</label> <input type="email" name="email" id="email" value="" /> <label for="password">Password:</label> <input type="password" name="password" id="password" value="" /> <input type="button" id="btnLogin" value="Login" onclick="callservice();"/> </fieldset> </form> </div> <!-- end content --> <div data-role="footer"> <h4>Page Footer</h4> </div> </div> <div data-role="page" id="divResponse"data-title="test"> </div> </div> </body> </html>
bon normalement ne fois le login et le password tapé, si on clique sur le bouton login la webmethod Authentifier doit être appeler, cependant rien ne se passe !! et j'arrive pas à cerner le problème;Merci de me donner un coup de main
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
50
51
52 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Security; using System.Data.SqlClient; namespace Test { /// <summary> /// Description résumée de authentification /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // Pour autoriser l'appel de ce service Web depuis un script à l'aide d'ASP.NET AJAX, supprimez les marques de commentaire de la ligne suivante. [System.Web.Script.Services.ScriptService] public class authentification : System.Web.Services.WebService { [WebMethod] public string Authentifier() { password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5"); SqlConnection oConnexion = new SqlConnection("data source=./SQLDBExpress;Integrated Security=SSPI;Initial Catalog=Ahm"); SqlCommand oCommand = new SqlCommand("SELECT * FROM authentification WHERE Login='" + Login + "'", oConnexion); oConnexion.Open(); SqlDataReader reader = oCommand.ExecuteReader(); while (reader.Read()) { if (reader["Login"].ToString() != Login && reader["password"] != password) return "Nom utilisateur ou mot de passe invalide"; else { if (reader["Login"].ToString() == Login && reader["password"] == password) { return "OK"; } } } oConnexion.Close(); return ""; } } }
Partager