我有两个不同领域的项目。
Apache cordova和webapi ...
我发布请求时出现内部500错误。问题可能出在webapi配置中。
//global.asax.cs
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
}
protected void Application_BeginRequest()
{
if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS")
{
Response.Flush();
}
}
//script.js
$(document).ready(function () {
$("#datasubmit").click(function () {
var data = $("#data").val();
//alert(aracplaka);
$.ajax({
type: "post",
dataType: 'json',
url: "http://10.16.0.22:88/api/arac",
data: data,
success: alert("başarılı"),
error: function () {
alert("hata")
}
})
});
});