110,534
社区成员
发帖
与我相关
我的任务
分享
var header:URLRequestHeader = new URLRequestHeader("Content-Type", "application/json");
var request:URLRequest = new URLRequest("http://localhost:8001/Greeting.svc/SayHello");
request.method = URLRequestMethod.POST;
request.requestHeaders.push(header);
request.data = '{"name":"i am as3"}';
_urlLoader = new URLLoader();
_urlLoader.addEventListener(Event.COMPLETE, completeHandle);
var header:URLRequestHeader = new URLRequestHeader("Content-Type", "application/xml");
var request:URLRequest = new URLRequest("http://localhost:8001/Greeting.svc/SayHello");
request.method = URLRequestMethod.POST;
request.requestHeaders.push(header);
request.data = "<name>i am as3</name>";
_urlLoader = new URLLoader();
_urlLoader.addEventListener(Event.COMPLETE, completeHandle);
[OperationContract]
[WebInvoke(ResponseFormat = WebMessageFormat.Xml)]
public String SayHello(String name)
{
return name;
}
request.data = '<SayHello xmlns="HelloServices"><name>abc</name></SayHello>'
其中HelloServices是WCF的命名空间
同理,在ajax里也是同样
jQuery.ajax({
type: "post",
async: false,
url: "Greeting.svc/SayHello",
data: '{"name":"i am as3"}',
data: '<SayHello xmlns="HelloServices"><name>abc</name></SayHello>',
contentType: "application/xml; charset=utf-8",
dataType: "json",
cache: false,
success: function (data) {
//返回的数据用data.d获取内容
alert(data.d);
}
});