XML分析错误:找不到元素
我有一个ASP.Net 4.0 Web服务方法,它返回一个格式良好的XML文档。我在本地成功地在浏览器中显示XML,并将其部署在生产服务器上。XML分析错误:找不到元素
当我尝试调用通过jQuery AJAX我得到了错误的方法:
XML解析错误:没有的元素中找到位置:MOZ-nullprincipal:{6c0c99b3-0fed-454f-aa6e-e0fca93a521c} 1号线,1列:
$.ajax(
{
url: 'http://mywebservice.com/WebService/Service.asmx/UserData',
type: 'GET',
contentType: "text/html; charset=utf-8",
dataType: "xml",
data: 'authorizedId=1234&authorizedUser=Test&authorizedCode=xyz',
'success': function (data) {
$('#XMLContent').html(data.responseText);
},
'error': function (xhr, status) {
alert(status);
},
'complete': function (xhr) {
}
});
我试图改变的contentType,但相同的结果。
不过,我可以作出这样在C#中的电话,我让我的格式良好的XML:
XmlDocument document = new XmlDocument();
document.Load("http://mywebservice.com/WebService/Service.asmx/UserData?authorizedId=1234&authorizedUser=Test&authorizedCode=xyz");
ViewData["XMLData"] = document.OuterXml;
在我的web服务的web.config:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
谢谢...
如果Web服务与页面不在同一个域中,则不能使用AJAX调用从其他域中获取数据。
您可以在您的应用程序中创建代理Web服务,然后调用您的外部Web服务,然后从AJAX/jQuery调用您自己的代理。
http://forum.jquery.com/topic/jquery-ajax-and-xml-issues-no-element-found
希望帮助
感谢bgs264 ...
现在在我的aspx页面:
$.ajax(
{
url: '/Home/WebService',
type: 'GET',
contentType: "text/html",
dataType: "html",
data: 'authorizedId=1234&authorizedUser=Test&authorizedCode=xyz',
'success': function (data) {
alert(data);
$('#XMLContent').html(data);
},
'error': function (xhr, status) {
alert(status);
},
'complete': function (xhr) {
}
});
在我的MVC控制器:
public ActionResult WebService(string authorizedId, string authorizedUser, string authorizedCode)
{
XmlDocument document = new XmlDocument();
document.Load("http://mywebservice.com/WebService/Service.asmx/UserData?authorizedId=" + authorizedId + "&authorizedUser=" + authorizedUser + "&authorizedCode=" + authorizedCode);
ViewData["XMLData"] = document.OuterXml;
return PartialView();
}
这个修复了吗?如果是这样,请点击旁边的勾号将我的答案标记为答案:)谢谢。 – bgs264 2011-03-22 13:56:14
我更改d Web服务调用返回一个简单的“字符串”而不是XML文档:仍然收到XML解析错误。顺便说一句 - 总是得到200响应。 – tom 2011-03-18 13:24:34
已解决?我有类似的东西,我正在寻找答案。 – nadavy 2012-02-21 20:54:59