解析错误 - 无效的xml

时间:2016-04-19 00:41:09

标签: ajax xml webmethod

我有这个客户端代码:

 $.ajax({
            url: "Sport.aspx/GetSoccer",                     
            type: "POST",
            data: '{strurl: "", post: "" }',
            cache: false,
            dataType: "xml",
            processData: false,
            success: function (data) {
                var valid = $(data).find("Validate").text() == '0';
                if (valid == true) {
                    PrintXml(data);
                } else {
                    alert("error");
                }
                removeLoading()
            },
            error: function (data, e, r) {
                removeLoading()
            }
        });

和此服务器端代码

<ScriptMethod(ResponseFormat:=ResponseFormat.Xml, XmlSerializeString:=True)>
<System.Web.Services.WebMethod(BufferResponse:=False)>
Public Shared Function GetSoccer(strurl As String, post As String) As String
    Dim request As WebRequest = WebRequest.Create("http://www.domain.com/Client/Details.aspx")


    Try
        request.Method = "POST"
        Dim postData As String = "off=10&u=1&m=0"
        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
        request.ContentType = "text/xml" '  "application/x-www-form-urlencoded"
        request.ContentLength = byteArray.Length
        Dim dataStream As Stream = request.GetRequestStream()
        dataStream.Write(byteArray, 0, byteArray.Length)
        dataStream.Close()
        Dim response As WebResponse = request.GetResponse()
        'Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
        dataStream = response.GetResponseStream()
        Dim reader As New StreamReader(dataStream)
        Dim responseFromServer As String = reader.ReadToEnd()
        reader.Close()
        dataStream.Close()
        response.Close()
        Return responseFromServer
    Catch ex As Exception
        Return Nothing
    End Try

我收到此错误:parseerror,xml无效   这是在调试结果中

Parseerror - invalid XML   我还尝试将数据类型从xml更改为json和text,但结果不会更改

由于

0 个答案:

没有答案