-1

This js fire server side api call and C# successfully return too but it come in error function in js. and i can not see result in response error.

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# Code

 [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);
            }
        }
SOF User
  • 7,590
  • 22
  • 75
  • 121
  • The title of your question says "JSONP", however, your JQuery settings specify "JSON" as a datatype - could you clarify which it is you're trying to achieve. In addition, have you a) tried debugging to ensure that your ModelState.IsValid is true and b) tried viewing the actual JSON response generated by the call? This may lend some clues...if (a) the ModelState isn't valid then you will hit the error event, and (b) if it isn't valid JSON being returned then you could potentially hit the error event. – tristankoffee Nov 13 '12 at 15:57

1 Answers1

0

You will need to make sure that you use includeExceptionDetailInFaults="True" in your web.config (and any WCF declarations). Compile it in DEBUG mode to ensure that you get the maximum exception detail.

EDIT: Turn it off again when going to production!!

Dan Ware
  • 396
  • 2
  • 9