我有wcf方法:
[OperationContract]
[WebInvoke(UriTemplate ="TestFunction", Method = "POST",ResponseFormat =WebMessageFormat.Json,RequestFormat =WebMessageFormat.Json,BodyStyle =WebMessageBodyStyle.WrappedRequest)]
string TestFunction(string name);
public string TestFunction(string name)
{
return "Successed!";
}
我的ajax方法:
<script type="text/javascript">
$(function () {
var wcfurl='http://192.168.200.100/Searching.BE.Service/WCFRESTService.svc/TestFunction';
$.support.cors = true;
jQuery.support.cors = true;
$.ajax({
crossDomain: true,
type: 'POST',
processdata: true,
data:{"name":"Denis"},
url: wcfurl,
success: function (data) { alert(data); },
error: function (data) { console.log(data);},
ContentType: 'application/json; charset=utf-8',
dataType: 'json',
});
});
</script>
返回服务:
{readyState: 4, responseText: "<?xml versi...", status: 400, statusText: "Bad Request"}
我尝试过使用JSON.string等等。问题是什么?