Jquery ajax代码出错了部分

时间:2017-09-07 10:11:21

标签: javascript c# jquery asp.net ajax

我已经调用了一个javascript函数,其中我正在使用ajax。但我不知道为什么它总是在function BindHTMLTable() { var structureName = $('#<%=ddlFacilityId.ClientID %>').val(); var facilityID = $('#<%=ddlFacilityId.ClientID %> :selected').text(); $.ajax({ url: "UBRDashboard.aspx/GETSTRUCTUREINFO", dataType: "json", type: "POST", contentType: 'application/json; charset=utf-8', data: JSON.stringify({ facilityID: facilityID, structureName: structureName }), async: true, processData: false, cache: false, success: function (r) { alert('page loaded'); }, error: function (xhr) { alert('Error while selecting list..!!'); } }) } 部分。以下是代码

public static string GETSTRUCTUREINFO(string facilityID, string structureName)
    {
        string strStructure = "";
        try
        {
            DataTable dtStructureInfo = CommonDB.GET_STRUCTURE_DETAILS(facilityID, structureName);                
        }
        catch (Exception ex)
        {                
            throw ex;
        }
        return strStructure;
    }

服务器端功能

{{1}}

1 个答案:

答案 0 :(得分:2)

将此装饰添加到服务器端方法

[System.Web.Services.WebMethod()]

您可以像这样创建生成的html表:

$("button").click(function() {
  var data = [
   {"RJ_NETWORK_ENTITY_ID":"INUESTPRISMLTW0001ENBRRH003","EQUIPMENT_NAME":"RAN:RR::577569"},
   {"RJ_NETWORK_ENTITY_ID":"INUESTPRISMLTW0001ENBRRH002","EQUIPMENT_NAME":"RAN:RRU::577571"}
  ];

  // Just get handle for the existing table
  var table = $("#tblData");

	// Clear table
  table.empty();

  // Create header row
  var header = $("<tr><th>RJ Network Entity ID</th><th>Equipment Name</th></tr>");
  table.append(header);

  // Create rows
  data.forEach(function(dataRow) {
    var tr = $("<tr>");
    $.each(dataRow, function(key,value) {
      tr.append("<td>" + value + "</td>");
    });
    table.append(tr);
  });
});
table, td, th {
  border: 1px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="tblData"></table>

<button>
fill table
</button>