how to refer xml file from client side application which is generated by webservice
This is my code on the webservice which sucessfully creates the xml file and saves at particular destination folder.
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;
}
I am trying to read that file from clientside application with the following code,but i am facing some problem with it.
开发者_StackOverflow中文版$.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);
........................................
.......................................
your url should be the complete path on the web
e.g.
var searchUrl ="http://yourdomain/Block3.xml"
;
I see that you are saving the file in documents and settings. you should not save it that location.
From javascript in a browser you can't access the file system of the server (even if the server is the local host).
You probably want to save the xml file to a location that can be accessed via http request, and use that URL from your script to actually retrieve the file.
精彩评论