dongmiao260399 2018-03-25 10:36
浏览 39

如何在php e javascript中使用C#DataTable

i'm working on a html/javascript/php application that call a c# web service. The web service built in c# retrieve data from mysql and returns a DataTable.

I'm calling a php file from ajax:

define(["jquery"], function() {
  $(document).ready(function() {

    $.ajax({
      type: "POST",
      url: "/ajaxcall/getAllAziende.php",
      DataType : 'json',
    success: function(data){
      console.log(data);
    },
    error: function(xhr, textStatus, error){
      console.log(xhr.statusText);
      console.log(textStatus);
        console.log(error);
    },
      failure: function(errMsg) {
                console.log("failure" + errMsg);
      }
   })
  })
});

This file call the web service:

<?php
   $client = new SoapClient('http://192.168.0.5/pass_app/WebService1.asmx?wsdl');

   $result = $client->getAllAziende();

   $decresult = json_decode(json_encode($result), True);
   $out = $decresult['getAllAziendeResult'];
print_r($out);

   $output = json_encode($result);
   echo $output;
?>

the print_r returns:

 [
{
  "ragione_sociale": "cinciallegraSRL",
  "via": null,
"cap": null,
"localita": null,
"provincia": null,
"telefono": null,
"fax": null,
"id_settore": null,
"id_attivita": null,
"note": null,
"id": 1
},
{
"ragione_sociale": "dwdwwdw",
"via": "",
"cap": "",
"localita": "",
"provincia": "",
"telefono": "",
"fax": "",
"id_settore": "",
"id_attivita": "",
"note": "",
"id": 2
},
{
"ragione_sociale": "pippo",
"via": "pluto",
"cap": "pape",
"localita": "",
"provincia": "",
"telefono": "",
"fax": "",
"id_settore": "",
"id_attivita": "",
"note": "",
"id": 4
}
]

I dont' know hot to consume this result in javascript, at the moment console.log(data) returns:

{"getAllAziendeResult":"[
  {
    \"ragione_sociale\": \"cinciallegraSRL\",
    \"via\": null,
    \"cap\": null,
    \"localita\": null,
    \"provincia\": null,
    \"telefono\": null,
    \"fax\": null,
    \"id_settore\": null,
    \"id_attivita\": null,
    \"note\": null,
    \"id\": 1
  },

  {
    \"ragione_sociale\": \"dwdwwdw\",
    \"via\": \"\",
    \"cap\": \"\",
    \"localita\": \"\",
    \"provincia\": \"\",
    \"telefono\": \"\",
    \"fax\": \"\",
    \"id_settore\": \"\",
    \"id_attivita\": \"\",
    \"note\": \"\",
    \"id\": 2
  },

  {
    \"ragione_sociale\": \"pippo\",
    \"via\": \"pluto\",
    \"cap\": \"pape\",
    \"localita\": \"\",
    \"provincia\": \"\",
    \"telefono\": \"\",
    \"fax\": \"\",
    \"id_settore\": \"\",
    \"id_attivita\": \"\",
    \"note\": \"\",
    \"id\": 4
  }
]"} 

Can somebody help me please? Thank you!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab中使用gurobi时报错
    • ¥15 WPF 大屏看板表格背景图片设置
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂