Reputation: 7830
When I pass this request it pass null to request parameter on server site. Is there any wrong with data attribute?
$.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; }
}
Upvotes: 0
Views: 137
Reputation: 1166
It's a problem with the model binding. Start with trying this:
$.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!');
});
if this above doesn't work, try this. I took this from some code I have doing the exact same thing you are attempting.
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');
Upvotes: 0
Reputation: 146300
Try this out instead:
data: {"request":'{"SubDomain":"asfsadf","ParentDomain":"asfasdf","ResellerId":"asfdsd"}'},
Upvotes: 1