Client-side JS does not require any special settings, using the usual Ajax calls:
$.ajax ({ URL: ' Cross-domain URL ', type: ' Get ', dataType: ' json ', success:function (data) { $ (' #banner_ Right '). HTML (data);} });
The server needs to add the following code in Webapiconfig.register ()
public static class webapiconfig{public static void Register (httpconfiguration config) { var cors = new Enab Lecorsattribute ("http://www.cnblogs.com,http://news.cnblogs.com", "*", "*"); Config. Enablecors (cors); }}
Note 1: "http://www.cnblogs.com,http://news.cnblogs.com" means that the 2 domain names are allowed to invoke this web API across domains.
NOTE 2: NuGet installation Required Microsoft.AspNet.Cors
How to invoke the ASP. Cross-domain call to the NET Web API (how do I implement an ASP call across domains using HTTP get in JavaScript?) )