[英]Trying to output HTML from Jquery $.ajax call to web service
I am trying to return an html table from a asp.net web service but can not figure out how to get the string that is returned to be actual html. 我正在尝试从asp.net Web服务返回html表,但无法弄清楚如何获取返回为实际html的字符串。 Here is my jquery call... 这是我的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");
}
})
it returns the string in the format I want but just writes out the string to the screen which is the string representation of an html table. 它以我想要的格式返回字符串,但只是将字符串写到屏幕上,即html表的字符串表示形式。 How do I get the actual Html table to render? 如何获取实际的HTML表格进行渲染?
change $('#tblPeople').text(obj.d);
更改$('#tblPeople').text(obj.d);
to -> $('#tblPeople').html(obj.d);
到-> $('#tblPeople').html(obj.d);
Since you are returning HTML you need to drop the JSON parts of your call and use the HTML() call rather than text() 由于您要返回HTML,因此需要删除调用的JSON部分并使用HTML()调用而不是text()
$.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");
}
});
Figured out he issues. 找出他的问题。 I was using $('#tblPeople').text(obj.d); 我正在使用$('#tblPeople')。text(obj.d); instead of $('#tblPeople').html(obj.d); 而不是$('#tblPeople')。html(obj.d);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.