1

I am trying to make cross domain call to get some HTML , I am getting below error please some one can help me what need to be done. below is error which i am getting.

"Error" : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://test.com/webclient/widget/GetPromotionalBanner/%7bA301A86A-87CB-4F49-BF0E-A8EE355295BD%7d/Bright. (Reason: missing token 'access-control-allow-origin' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channel).

Always going on error section.

JAVASCRIPT CODE

(function ($) {
'use strict';
//==================================================
// DOCUMENT READY 
//--------------------------------------------------
function mytest(ss){
    console.log(ss);
}
$.ajax({
    type: "Get",
    url:"http://mytesturl.com",
    cache: "false",
    headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Request-Headers':'X-Custom-Header','Access-Control-Request-Method':"GET"},
    crossDomain : true,
    success: function(html) {
        alert("Cross Domain Call Success");
        console.log(html);
    },
    error:function(error){
        alert("Error Response :", error);
        console.log(error);
    }
});

//--------------------------------------------------
// end DOCUMENT READY...
//==================================================
}(jQuery));

Respone Header of Ajax call

Access-Control-Allow-Orig... * Cache-Control private Content-Encoding gzip Content-Length 886 Content-Type text/html; charset=utf-8 Date Mon, 18 Jul 2016 07:46:49 GMT Server Microsoft-IIS/8.5 Set-Cookie ASP.NET_SessionId=pe1r0iiklzj5ch3fuanhzlun; path=/; HttpOnly SC_ANALYTICS_GLOBAL_COOKIE=a874641e69b948898f6dcb596a987fbc|False; expires=Sat, 18-Jul-2026 07:46:49 GMT; path=/; HttpOnly Vary Accept-Encoding X-AspNet-Version 4.0.30319 X-AspNetMvc-Version 5.2 X-Powered-By ASP.NET

Request Header Accept text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Encoding gzip, deflate Accept-Language en-US,en;q=0.5 Access-Control-Request-He... access-control-allow-origin Access-Control-Request-Me... GET Cache-Control max-age=0 Connection keep-alive Host test.com Origin null User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0

Ban_meg
  • 31
  • 6

1 Answers1

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

this header must be set on the server, not in AJAX request.

Alexey
  • 980
  • 5
  • 12