这是我在 Web 服务上的代码,它成功创建了 xml 文件并保存在特定的目标文件夹中。
public bool GetList(string keyword1, string streetname, string lat, string lng, string radius)
{
XmlDocument xmlDoc= CreateXML( keyword1,streetname,lat,lng,radius);
xmlDoc.Save(@"C:\Documents and Settings\block\Block3.xml");
return true;
}
我正在尝试使用以下代码从客户端应用程序读取该文件,但我遇到了一些问题。
$.ajax({
type: "POST",
async: false,
url: "/block/JsonWebService.asmx/GetList",
data: keyword2,
contentType: "application/json; charset=utf-8",
dataType: "json",
failure: ajaxCallFailed,
success: ajaxCallSucceed
});
});
function ajaxCallSucceed(response) {
if (response.d == true) {
searchLocationsNear();
}
else {
alert("can not save");
}
}
function searchLocationsNear() {
var radius = document.getElementById('radiusSelect').value;
var searchUrl ="Block3.xml";// is this the correct way to refer to the
xml file stored in app folder
GDownloadUrl(searchUrl, function(data) {
var xml = GXml.parse(data);
........................................
.......................................
最佳答案
您的网址应该是网络上的完整路径
例如
var searchUrl ="http://yourdomain/Block3.xml"
;
我发现您正在将文件保存在文档和设置中。您不应该将其保存在该位置。
关于c# - 如何从Web服务生成的客户端应用程序引用XML文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3636338/