0

このリクエストを渡すと、サーバー サイトのリクエスト パラメータに null が渡されます。データ属性に誤りはありませんか?

$.getJSON('http://127.0.0.1:81/api/sites/GetDomainAvailability?apikey=asfasfdsf&callback=?', { "request": '{"SubDomain":"asfsadf","ParentDomain":"asfasdf","ResellerId":"asfdsd"}' }, function (results) {

    alert('Cross domain JS call achieved. Have your implementation going in here!');
});

API C#

[HttpGet]
public HttpResponseMessage GetDomainAvailability(GetDomainAvailabilityRequest request)
{
    if (ModelState.IsValid)
    {
        if (request == null) return Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Request");
        var domain = string.Format("{0}.{1}", request.SubDomain, request.ParentDomain);

        var manager = new CloudSitesManager();
        var isDomainAvailable = manager.GetDomainAvailability(domain);

        HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, isDomainAvailable);
        return response;
    }
    else
    {
        return Request.CreateResponse(HttpStatusCode.BadRequest);
    }
}

[Serializable]
public class GetDomainAvailabilityRequest
{
    public string SubDomain { get; set; }
    public string ParentDomain { get; set; }
    public string ResellerId { get; set; }
}
4

2 に答える 2

1

代わりにこれを試してください:

data: {"request":'{"SubDomain":"asfsadf","ParentDomain":"asfasdf","ResellerId":"asfdsd"}'},
于 2012-11-13T14:55:59.667 に答える
0

モデルバインディングの問題です。これを試すことから始めます:

$.getJSON('http://127.0.0.1:81/api/sites/GetDomainAvailability', {SubDomain:"asfsadf",ParentDomain:"asfasdf",ResellerId:"asfdsd"}, function (results) {

    alert('Cross domain JS call achieved. Have your implementation going in here!');
});

上記がうまくいかない場合は、これを試してください。これは、あなたが試みているのとまったく同じことを行っているコードから取得しました。

var data = { SubDomain: "asfsadf", ParentDomain: "asfasdf", ResellerId: "asfdsd" };

$.post('http://127.0.0.1:81/api/sites/GetDomainAvailability', data, function (results) {

    alert('Cross domain JS call achieved. Have your implementation going in here!');
}, 'json');
于 2012-11-13T15:22:13.360 に答える