这个 js 触发服务器端 api 调用和 C# 也成功返回,但它在 js 中出现错误函数。而且我看不到响应错误的结果。
JS
$.ajax({
url: "http://127.0.0.1:81/api/sites/GetDomainAvailability?apikey=asfasfdsf&callback=?",
data: { subDomain: subDomain, parentDomain: parentDomain, resellerId: resellerId },
contentType: 'application/json; charset=utf-8',
accept: 'application/json',
dataType: 'json',
success: function (response) {
if (callback)
callback(response.d);
},
error: function (response) {
if (callback)
error(response.d);
}
});
C# 代码
[HttpGet]
public HttpResponseMessage GetDomainAvailability(string subDomain, string parentDomain, string resellerId)
{
if (ModelState.IsValid)
{
var domain = string.Format("{0}.{1}", subDomain, parentDomain);
var manager = new CloudSitesManager();
var isDomainAvailable = manager.GetDomainAvailability(domain);
var response = Request.CreateResponse(HttpStatusCode.OK, isDomainAvailable);
return response;
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}