2

I have request json data from other website, but it meets the problem of access control allow origin in header, I have no idea how to set the access control allow origin in header, I'm put my source code in the iis8 to access the json data from another iis8 api source.

$.ajax({
    type: "GET",
    url:rootURL,
    xhrFields: {
        withCredentials: false
    },

    headers: {
      "Access-Control-Allow-Origin: ": "*",
      "Access-Control-Allow-Methods: ": "GET",
      "Access-Control-Allow-Headers: ": "Authorization",
    },
    dataType: "json",
    success: function(data) {   
    },
    error: function() {
        alert("An error occurred while processing JSON file.");
    }
});     
Praveen Kumar Purushothaman
  • 154,660
  • 22
  • 177
  • 226
Elice Ee
  • 119
  • 1
  • 1
  • 10

1 Answers1

5

These should be in the server, not the client:

"Access-Control-Allow-Origin: ": "*",

To implement that in server, for PHP:

<?php
  header("Access-Control-Allow-Origin: *");

For ASP.NET:

Response.AppendHeader("Access-Control-Allow-Origin", "*");

For others, check I want to add CORS support to my server for more information.

Praveen Kumar Purushothaman
  • 154,660
  • 22
  • 177
  • 226
  • 1
    Thank you so much!!! I have solve it with it~ But now for the other method like put, delete, update, it occurs Response for preflight has invalid HTTP status code 404 error May I know how to solve it in proper, tq so much – Elice Ee Jan 06 '16 at 03:47