0

I have hosted WCF service to cloud & if I POST ajax call then it's behaving properly.

enter image description here

Where as when I am posting it from other web page then I am getting OPTIONS HTTP.

enter image description here

Now if I go to the IE browser & enable the Access data sources across domain then it's working properly.

enter image description here

I made some changes go my WCF service as well like: Added global.asax class file & POST header is case it's get OPTIONS:

protected void Application_BeginRequest(object sender, EventArgs e)
{
  HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
  HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
  HttpContext.Current.Response.AddHeader("Access-Control-Allow-Credentials", "true");
  HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
  HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
  HttpContext.Current.Response.End();
}

JavaScript code:

  $.ajax({
            type: "POST",
            url: url,
            processData:false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: null,
            success: function(data)
            {
                alert(data.LeadCreated);
            }
        });
Deep
  • 101
  • 9

0 Answers0