J'ai un web service WCF, et j'aimerais pouvoir afficher les données d'une méthode dans une dataTable depuis un fichier JavaScript.
Voici ma méthode dans mon web service:
Voici la classe ResponseStatistic_1.cs
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)] ResponseStatistic_1 Statistic_1();
Code c# : 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 public class ResponseStatistic_1 : IBaseClientEntity { public ResponseStatistic_1() { } public ResponseStatistic_1(Statistic_1 [] items) : this() { this.Items = items; } public Statistic_1[] Items { get; set; } }
Voici la classe Statistic_1.cs :
Code c# : 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 public class Statistic_1 { private string _geografisch_zone; private decimal[] _sum; private int _yearStart; private int _yearEnd; public Statistic_1() { ... } public string Geografisch_zone {... } public decimal[] Sum { ... } public int YearStart { ... } public int YearEnd { ... } }
Et mon code JavaScript :
Comment je fais pour récupérer les données de cet objet ResponseStatistic_1?
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 function getStatistic1() { var response; var allstat1 = []; $.ajax({ type: 'GET', url: 'http://localhost:52768/Service1/Statistic_1', contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (msg) { response = msg.d; for (var i = 0; i < response.length; i++) { allstat1[i] =**???** } fillData(allstat1);**???** }, error: function (e) { alert("error loading statistic 1"); } }) } function fillData(data) { $('#table_campaigns').dataTable({ **???** }); }
Il me met comme erreur que "response is undefined".
Merci.
Partager