can we return xml document to client side application instead of saving it at particular destination
I have a webservice webmethod which saves the xml output to destination
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlDocument GetList(
string keyword1, string streetname, string lat, string lng, string radius)
{
XmlDocument xmlDoc = CreateXML( keyword1,streetname,lat,lng,radius);
//save file to application folder which will be refferd by client application
xmlDoc.Save(Server.MapPath("~/Block3.xml"));
return xmldoc;
}
I am trying to refer from client side using the following code in searchurl
function searchLocationsNear() {
var radius = document.getElementById('radiusSelect').value;
开发者_JS百科 var searchUrl ="http://localhost:2385/block/Block3.xml"; //reference for xml file stored in application folder
GDownloadUrl(searchUrl, function(data) {
var xml = GXml.parse(data);
The following is a simple example of how you might use jQuery to call the server side WebMethod from the client side. This code assumes that you are hosting the searchLocationNear(...) method in WebService1.asmx
function searchLocationNear() {
// Get the radius using jQuery
var radius = $("#radiusSelect").val();
// Make Ajax call using jQuery
$.ajax({
type: "POST",
data: "keyword1=&streetname=&lat=&lng=&radius=" + radius,
url: "WebService1.asmx/GetList",
success: function (response) {
var xml = GXml.parse(response.xml);
},
error: function (response) {
alert(response.responseText);
}
});
}
Here $.ajax is used to make a call to the GetList web method, and the XML is extracted from the response. This works find if you are returning an XmlDocument on the server side as in your case.
One way could be to:
- Call the web method from javascript
- Use XmlDocument object in javascript
加载中,请稍侯......
精彩评论