简体   繁体   中英

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. Here is my jquery call...

$.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. How do I get the actual Html table to render?

change $('#tblPeople').text(obj.d); to -> $('#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()

$.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); instead of $('#tblPeople').html(obj.d);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM