Problem with posting xml data to .net webservice asmx
I have the following code which is trying to post xml constructed data to webservice .asmx but xml constructed data is not reaching webservice file at all.when i make ajax call control is not moving to webservice file at all.Is their any problem with syntax in ajax. This is my code on client side .
$.ajax({
type: "POST",
async: false,
url: "/blkseek2/JsonWebService.asmx/GetList",
datatype:"xml",
data:"<?xml version='1.0'?><keyword1>"+keyword1+ "</keyword1><streetname>"+address1+ "</streetname><lat>"+lat+开发者_StackOverflow"</lat><lng>"+lng+ "</lng><radius>"+radius+"</radius>" ,
contentType: "application/xml; charset=utf-8",
// processData: false,
failure: function(XMLHttpRequest, textStatus, errorThrown)
{ ajaxError(XMLHttpRequest,textStatus, errorThrown); },
success: function(xml)
{ ajaxFinish(xml); }
});
This is my webmethod code in webservice which is trying to return xml file as output for the request
[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);
return xmldoc;
}
Your ajax call shouldn't be in XML format.
Change your data to something like this:
data:{ "keyword1:'" + keyword1 + "',streetname:'" + address1 + "',lat:" + lat + ",lng:" + lng + ",radius:" + radius}
EDIT: I just noticed your lat, lng and radius are strings (WHY?). Anyhow, because of that, try this:
data:{ "keyword1:'" + keyword1 + "',streetname:'" + address1 + "',lat:'" + lat + "',lng:'" + lng + "',radius:'" + radius + "'"}
精彩评论