【问题标题】:Trying to output HTML from Jquery $.ajax call to web service尝试从 Jquery $.ajax 调用输出 HTML 到 Web 服务
【发布时间】:2009-07-17 12:40:55
【问题描述】:

我正在尝试从 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 表?

【问题讨论】:

    标签: jquery html ajax


    【解决方案1】:

    $('#tblPeople').text(obj.d); 更改为 -> $('#tblPeople').html(obj.d);

    【讨论】:

      【解决方案2】:

      由于您要返回 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");
             } 
      });
      

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 2013-08-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-12-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多