2

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+"</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;

}

1 Answer 1

1

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 + "'"}
Sign up to request clarification or add additional context in comments.

4 Comments

I wouldnt say "shouldnt". Its bizarre, i agree - but its totally acceptable to post xml to a web service.
I've not seen a successful Jquery ajax call that works by posting the parameters in XML format. Mostly, because the Jquery API converts the "data" parameter to a query string. You can send XML INSIDE a parameter.
Thanks for your reply ,suggest me any if their are any good article which tries to post some data to webservice and get the reply back as xml file.
@mahesh Try changing datatype to dataType (notice the uppercase T)? Also try this if you need to parse your XML: think2loud.com/reading-xml-with-jquery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.