2

I have the following code where i construct json data and send to the webservice ,my datatype will be json and response from the webservice will be in xml format does this logic work out or do i need to stick to any one particular datatype either json or xml.

var keyword2 = "{\"keyword1\":\"" + keyword1 + "\",\"streetname\":\"" + address1 + "\",\"lat\":\"" + lat + "\",\"lng\":\"" + lng + "\",\"radius\":\"" + radius + "\"}";

//keyword2 will be my json constructed data ,will it be same in case of xml construction $.ajax({ type: "POST", async: false, url: "/blkseek2/JsonWebService.asmx/GetList", datatype:"json", data:keyword2, contentType: "application/xml; charset=utf-8",

             failure: function(XMLHttpRequest, textStatus, errorThrown) 
                     { ajaxError(XMLHttpRequest,textStatus, errorThrown); },
                success: function(xml) 
                 { ajaxFinish(xml); }

// success: ajaxCallSucceed, // dataType: "xml", // failure: ajaxCallFailed }); });

2 Answers 2

2

See here: http://api.jquery.com/jQuery.ajax/

contentType and dataTypeString are the 2 u need. Like this:

$.ajax(
    {
        type: "POST",
        url: "/prom/" + project + "/Safety/GenerateMapping",
        data: "{\"keyword1\":\"" + keyword1 + "\",\"streetname\":\"" + address1 + "\",\"lat\":\"" + lat + "\",\"lng\":\"" + lng + "\",\"radius\":\"" + radius + "\"}",
        dataType: "json",
        contentType: "xml",
        failure: function(XMLHttpRequest, textStatus, errorThrown) 
                 { ajaxError(XMLHttpRequest,textStatus, errorThrown); },
        success: function(xml) 
             { ajaxFinish(xml); }
     });
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply , I pass json data to webservice from keyword data , will i be able to capture response in success where i will write code to parse the returned xml
1

Yes, just send the JSON object and use eval to get the JSON object using Javascript.

Check this out :

http://www.json.org/js.html

Comments

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.