views:

20

answers:

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 }); });

+1  A: 

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

abhishek
+2  A: 

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); }
     });
bruno
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
mahesh