AJAX响应带有未定义/对象文档

AJAX response with undefined/object document

本文关键字:对象 文档 未定义 响应 AJAX      更新时间:2023-09-26
  1. 我的第一个问题是,我有一个与服务器进行表单交换的脚本。服务器能够读取表单并发送响应。当我尝试打印回复时,下面显示的是我收到的内容。

    $('#myform').html(响应)//不会有回应alert(response)//它总是用[object Document]返回我。

所以当我把它改成下面时,它显示了我收到的:

$('#myform').html(response.xml);//it will return me with the xml value from my server
alert(response.xml)//normal xml value.

我可以在eclipse web浏览器中打印出来,但不能在任何其他浏览器(IE、firefox、chrome)上打印出来,它会返回未定义的内容。我做错什么了吗?我的服务器将返回我的html代码:

<table><tr><img src=https://lh6.googleusercontent.com/--WAwSUUNAG8/UdOVEZvpnuI/AAAAAAAABIk/aV-NzcMN2zg/s800/g.gif></tr></table>

2.第二个问题是如何将响应打印为html(即表)而不是明文。

下面是java脚本代码:

<script>
$(function() {  
  $(".button").click(function() {  
      var clin=$("input#client").val();
              var us=$("input#username").val();
              var dataString='client='+clin+'&username='+us;
      var res;
        $.ajax({  
              type: "POST",  
              url: "http://localhost:8080/services/web?wsdl/authen",  
              data: dataString, 
              success: function(response) {
                $('#myform').html(response);
                alert(response);
              }  
            }); 
            return false;   
  });  
});  
</script> 

这是服务器web服务:

<xs:element name="authen">
     <xs:complexType>
          <xs:sequence>
               <xs:element name="client" type="xs:string" nillable="true" minOccurs="0"/>
               <xs:element name="username" type="xs:string" nillable="true" minOccurs="0"/>
          </xs:sequence>
     </xs:complexType>
</xs:element>
<xs:element name="authenResponse">
     <xs:complexType>
          <xs:sequence>
               <xs:element name="return" type="xs:string" nillable="true" minOccurs="0"/>
         </xs:sequence>
     </xs:complexType>
</xs:element>

您调试该响应以查看其中的内容。

请尝试

dataType:'html',
success : function(data, status, response) {
    var obj = $("<div/>").html(response.responseText);
    $('#myform').html(obj.find("ns:return").html());
    alert(response.responseText);
}

还可以看看jQuery API文档

添加了dataType。

你的问题很不清楚,在我看来,你的回答不明确,这就是你的问题。也许可以尝试更改

"http://localhost:8080/services/web?wsdl/authen"

"/services/web?wsdl/authen"

或更改

data: dataString,

data: {
  client: clin,
  username: us
}