我尝试从jquery-Ajax脚本调用ASP.NET webservice方法时遇到“Root element is missing”错误,该脚本将contentType指定为application / json。经过几次检查后,我注意到来自服务器的响应类型与我期望的不同。
我真的被困在这里。
这是ajax调用:
$(document).on("pagecreate",function () {
//$('#abc').on('click', function(){
$(document).on('click', '#abc', function() {
var parameters;
$.ajax({
parameters: { "username": $("#username").serialize(),
"password": $("#password").serialize() },
type: "POST",
data: parameters,
url: "http://10.142.xxx.74/abc/Service.asmx?op=callgetUserLoginAuthentication",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: WSSucceed,
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
//failure: WSFailed
});
});
});
以下是来自firebug的错误:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: Root element is missing.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent()
at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
--- End of inner exception stack trace ---</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>
请咨询,我被困住了。
由于我的点数,我无法上传截图。