I'm writing some javascript that uses jQuery to make a webservice call.
I have a couple of questions:
If the webservice throws an exception (e.g. primary key constraint) will this cause a jQuery Ajax exception?
If I want to return a value, say the number of rows affected, do I have to use JSONP (because it is cross-domain)?
Update: I have to support IE8, so CORS isn't an option. Thanks to @Volodymyr and @mcv for pointing out that option
Still if you have control you can do following
public class AllowCrossSiteAttribute : ActionFilterAttribute {
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) {
if (actionExecutedContext.Response != null) {
actionExecutedContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
base.OnActionExecuted(actionExecutedContext);
}
}
}
Add this to you code (Please not that here you allow all domain but you can replace "*" with list of your domains), then on web api controller add this as attribute
Or using web config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Authorization" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>