【发布时间】:2016-09-17 18:24:28
【问题描述】:
这是我的 jQuery AJAX 方法:
$(document).ready(function() {
$("#btnSubmit").click(function() {
alert("Test");
var param = $("#txtEmail").val();
$.ajax({
url:"~/DemoService1.svc/IsEmailAvailable",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
//data: JSON.stringify({ Email: $('#txtEmail').val() }),
data: param,
success: function(msg) { //On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed
});
});
function ServiceFailed(result) {
alert('Service call failed: ' + result.status + ' ' + result.statusText);
Type = null;
varUrl = null;
Data = null;
ContentType = null;
DataType = null;
ProcessData = null;
}
});
这是我的服务接口。
[OperationContract]
[WebInvoke(UriTemplate = "/IsEmailAvailable", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
bool IsEmailAvailable(string Email);
我的 webconfig 是这样的:
<client>
<endpoint address="http://localhost:56537/DemoService1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDemoService1" contract="DemoService.IDemoService1"
name="BasicHttpBinding_IDemoService1" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehaviour" name="DemoService">
<endpoint address="" binding="webHttpBinding" contract="IDemoService1" behaviorConfiguration="EndBehaviour"></endpoint>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
请提供解决方案。我是 jQuery 新手。
【问题讨论】: