Binson Eldhose
Binson Eldhose

Reputation: 1013

how to call cross domain ajax calls using angular /Jquery

I have a application hosted with domain www.abc.com .This is actually WebApi application . I want to build a separate UI application using asp.net mvc, and its domain is www.xyz.com. The UI application consuming Angular,HTML5 and other Web technologies.Here i really need to perform GET,PUT,POST,DELETE against www.abc.com. unfortunately the limitation of jsonp , i like to choose CORS (HTML5 Cors), but i can't pass json object to CORS calls . what are the best possible best approach to call cross domain calls (GET,PUT,POST,DELETE) using angularJs with my problem scenario . What should i change in IIS to handle CORS request.

Upvotes: 0

Views: 2469

Answers (2)

harishr
harishr

Reputation: 18065

add below web.config in webapi

<system.webServer>
    <httpProtocol>
        <customHeaders>               
            <add name="Access-Control-Allow-Origin" value="*" />
        </customHeaders>
    </httpProtocol>
</system.webServer>

and in angular, set below config options for $http

header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://url.com:8080");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");

also check: this link

Upvotes: 2

aamir sajjad
aamir sajjad

Reputation: 3039

To enable cross domain ajax calls you can place crossdomain.config in asp.net web api root folder when published with following contents.

<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>

Upvotes: 0

Related Questions