Click here to Skip to main content
15,947,613 members

Comments by Member 12371381 (Top 1 by date)

Member 12371381 29-Mar-16 8:25am View    
i tried this but sttill i have a same issue.

i was getting foloowing isssue:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:42165/Service1.svc/GetData. (Reason: CORS preflight channel did not succeed).

i tried code like this.

var formEmployeeModule = angular.module("formEmpMod", []).controller("testcont",function($scope,$http) {
$scope.testMessage = "test message";

var compositeType = new Object();
compositeType.BoolValue = false;
compositeType.StringValue = "This is nanaji";


$scope.GetDataFromDb = $http({
ContentType: "application/json;charset=utf-8",
method: "POST",
processData: true,
crossDomain: true,
cache: false,
async: true,
dataType : 'jsonp',
url: "http://localhost:42165/Service1.svc/GetData",
// params: { value: '123'}
data:{composite:compositeType}
//http://localhost:42165/Service1.svc/GetData?value=123

}).then(function sucessCallBack(response) {

alert(response.data);
alert('this is sucess call black');
}, function errorCallback(response) {
alert(response.data);
alert('this is Failure call black');
} );


});


Rest service Server Web.Config:

<httpprotocol>
<customheaders>
<!-- Begin this is for angularJS configuration -->
<add name="Access-Control-Allow-Origin" value="*">
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS">
<add name="Access-Control-Max-Age" value="1728000">
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Access-Control-Allow-Origin">

<!-- End this is for angularJS configuration -->




In client Application Global.Asax file


protected void Application_BeginRequest(object sender, EventArgs e)
{

HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
//These headers are handling the "pre-flight" OPTIONS call sent by the browser
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Access-Control-Allow-Origin");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}