tags:

views:

1015

answers:

3

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?

A: 

Figured out he issues. I was using $('#tblPeople').text(obj.d); instead of $('#tblPeople').html(obj.d);

TampaRich
+2  A: 

change $('#tblPeople').text(obj.d); to -> $('#tblPeople').html(obj.d);

peirix
A: 

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");
       } 
});
AutomatedTester