In the actual development will provide WEBAPI to the front-end JS Direct call situation, there will be a cross-domain situation,
Solution:
Add code to Global
protected voidApplication_BeginRequest (Objectsender, EventArgs e) {HttpContext.Current.Response.AddHeader ("Access-control-allow-origin","*"); if(HttpContext.Current.Request.HttpMethod = ="OPTIONS") {HttpContext.Current.Response.AddHeader ("Access-control-allow-methods","*"); HttpContext.Current.Response.AddHeader ("access-control-allow-headers","*"); HttpContext.Current.Response.End (); } }
In the configuration file, add
<remove name= "Optionsverbhandler"/> <remove name= "Traceverbhandler"/>
<handlers> <Removename= "extensionlessurlhandler-integrated-4.0" /> <Removename= "WebDav" /> <Removename= "Optionsverbhandler" /> <Removename= "Traceverbhandler" /> <Addname= "extensionlessurlhandler-integrated-4.0"Path="*."verb="*"type= "System.Web.Handlers.TransferRequestHandler"Precondition= "integratedmode,runtimeversionv4.0" /> </handlers>
You can do it.
$.ajax ({ ' Http://api.zxsj.com/api/Job?strName=liuyl ', "Get", "json ", data: { // }, true, function (res) { $ (". Code"). Text (res. Code); $ (". Mess"). Text (res. Message); } );
WEBAPI Cross-domain requests