2009-07-17 53 views
0

我想從asp.net web服務返回一個html表,但無法弄清楚如何獲取返回爲實際html的字符串。這裏是我的jQuery的電話...

$.ajax({ 
       type: "POST", 
       url: "UserService.asmx/PersonTable", 
       data: "{}", 
       dataType: "json", 
       contentType: "application/json; charset=utf-8", 
       success: function(obj) { 
        alert(obj); 
        $('#tblPeople').text(obj.d); 
       }, 
       error: function() { 
        alert("error"); 
       } 
      }) 

返回字符串中我想要的格式,但只是寫出的字符串是一個HTML表的字符串表示的屏幕。我如何獲得實際的Html表格呈現?

回答

0

找出他的問題。 我正在使用$('#tblPeople')。text(obj.d);而不是$('#tblPeople')。html(obj.d);

10

變化$('#tblPeople').text(obj.d);到 - >$('#tblPeople').html(obj.d);

1

既然你回來,你需要刪除您的通話JSON部分,並使用HTML()調用,而不是文本()

$.ajax({ type: "POST", 
     url: "UserService.asmx/PersonTable", 
     data: "{}", 
     //dataType: "json", 
     //contentType: "application/json; 
     charset=utf-8", 
     success: function(obj) { 
        alert(obj); 
        $('#tblPeople').html(obj.d); 
     }, 
     error: function() { 
      alert("error"); 
     } 
}); 
HTML