weixin_33681778 2017-05-02 15:07 采纳率: 0%
浏览 58

在aspx页面中显示对象

I am working with webservice GetEmployeebyId, I get the object data and I would like to display it in a list using javascript in aspx page.

Please help me !!

here my code : it miss the function that display the object

**

<script>
    $(document).ready(function () {
        $.ajax({
            type: 'GET',
            url: _spPageContextInfo.webAbsoluteUrl + '/_vti_bin/EmployeeService.svc/GetEmployeebyNom/kmjdfb', // Location of the service
            contentType: 'application/json; charset=utf-8', // content type sent to server
            processdata: true,
            success: function (msg) {
            datasource:msg
            }
        });
    });
        </script>**

my object "msg" is found in this picture Object details

  • 写回答

1条回答 默认 最新

  • 关注

    The GetEmployeeByNom function must shows the employee details, then with your current object:

    {
        "Adresse": "hcs",
        "CIN": 516515,
        "Competence": "chc",
        "Contract": null,
        "Date_naissance": "Date(1490770800000-0700)/",
        "Email": "jbmkjb@hotmail.fr",
        "Etat_civil": "$Resources:TravelCasrdsFields,Single;",
        "Job_Title": "csv",
        "Nationalite": "hsvcsg",
        "Nom": "sdjhvc",
        "Prenom": "kmjdfb",
        "Sexe": "Mr",
        "Telephone": 65465
    }
    

    You should try with something like this:

    (function() {
    
      var msg = {
        "Adresse": "hcs",
        "CIN": 516515,
        "Competence": "chc",
        "Contract": null,
        "Date_naissance": "Date(1490770800000-0700)/",
        "Email": "jbmkjb@hotmail.fr",
        "Etat_civil": "$Resources:TravelCasrdsFields,Single;",
        "Job_Title": "csv",
        "Nationalite": "hsvcsg",
        "Nom": "sdjhvc",
        "Prenom": "kmjdfb",
        "Sexe": "Mr",
        "Telephone": 65465
      };
    
      // Include this function in your code.
      function displayEmployee(msg) {
        var ulList = "";
        ulList += "<ul>";
        for (var property in msg) { // For every property in the msg object.
          if (msg.hasOwnProperty(property)) { // Checks if the property exists.
            ulList += "<li><span>";
            ulList += property; // Gets the property name.
            ulList += "</span>: ";
            ulList += msg[property]; // Gets the property value.
            ulList += "</li>";
          }
        }
        ulList += "</ul>";
        return ulList; // Returns the ul tag with the data.
      }
    
      // Include this line in your success: function(msg) {} part.
      document.getElementById("EmployeeDetail").innerHTML = displayEmployee(msg);
    })();
    #EmployeeDetail ul {
      border: solid 1px #97bcd6;
      list-style-type: none;
      margin: 0;
      padding: 0;
    }
    
    #EmployeeDetail ul li {
      margin: 10px;
    }
    
    #EmployeeDetail ul li span {
      font-weight: bold;
    }
    <div id="EmployeeDetail">
    
    </div>

    Then, in the code that you have add document.getElementById("EmployeeDetail").innerHTML = displayEmployee(msg);

    $(document).ready(function() {
      $.ajax({
        type: 'GET',
        url: _spPageContextInfo.webAbsoluteUrl + '/_vti_bin/EmployeeService.svc/GetEmployeebyNom/kmjdfb', // Location of the service
        contentType: 'application/json; charset=utf-8', // content type sent to server
        processdata: true,
        success: function(msg) {
          document.getElementById("EmployeeDetail").innerHTML = displayEmployee(msg);
        }
      });
    });
    
    </div>
    
    评论

报告相同问题?