我有以下代码,我构建json数据并发送到webservice,我的数据类型将是json和webservice的响应将是xml格式这个逻辑是否工作或我需要坚持任何一个特定的数据类型json或XML .
var keyword2 =“{\”keyword1 \“:\”“keyword1”\“,\”streetname \“:\”“address1”\“,\”lat \“:\”“lat”\“,\”lng \“:\”“lng”\“,\”radius \“:\”“radius”\“}”;
// keyword2将是我的json构造数据,在xml构造的情况下是相同的 . $ .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 回答
看这里:http://api.jquery.com/jQuery.ajax/
contentType和dataTypeString是你需要的2 . 像这样:
是的,只需发送JSON对象并使用eval使用Javascript获取JSON对象 .
看一下这个 :
http://www.json.org/js.html