Access Control Allow Origin http set Headers

Access Control Allow Origin http set Headers

Simple Include headers Uing CORS solution (Cross-origin resource sharing)

Welcome to the In Pakainfo.com website! You will Step By Step learn web programming, easy and very fun. This website allmost provides you with a complete web programming tutorial presented in an easy-to-follow manner. Each web programming tutorial has all the practical examples with web programming script and screenshots available.For Access Control Allow Origin http set Headers

Access-Control-Allow-Origin – Name of the each domain allowed access control all for cross domain requests. * (* means all domain allowed)indicates all domains are allowed.
Access-Control-Allow-Methods – List of (GET, PUT, POST, DELETE, OPTIONS)HTTP methods can be used here domains during request.
Access-Control-Allow-Headers – List of (GET, PUT, POST, DELETE, OPTIONS)HTTP headers can be used here domains during request.

In PHP : “no ‘access-control-allow-origin’ header is present on the requested resource web api”

The Soltution of the no ‘access-control-allow-origin’ header is present on the requested resource web api in PHP.

// here include this three statement
header('Access-Control-Allow-Origin: *');  //all the methods access code
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS'); // all the resource and request get
header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');

simple Below the sample code which handles Cross Domain AJAX POST requests: post.php

CORS works fine in all the latest browsers, but IE8 and IE9 don’t support this.

In order to use XDomainRequest in IE, request must be:
a). Only GET or POST
When Posting, the data will always be sent with a Content-Type of text/plain
b). Only HTTP or HTTPS
Protocol must be the same scheme as the calling page
c). Always asynchronous

Step 1). Add the script in


Step 2). You need to set contentType value text/plain in $.ajax request.

 var contentType ="application/x-www-form-urlencoded; charset=utf-8";
 
if(window.XDomainRequest) //for IE8,IE9
    contentType = "text/plain";
 
$.ajax({
     url:"https://www.pakainfo.com/php/post.php",
     data:"name=king&age=28",
     type:"POST",
     dataType:"json",   
     contentType:contentType,    
     success:function(result)
     {
        alert("here Display all the Data from Server"+JSON.stringify(result));
     },
     error:function(jqXHR,textStatus,errorThrown)
     {
        alert("Error display :You can not any data send Cross Domain AJAX simple requests: "+errorThrown);
     }
    });
	

Below is the sample code, works in all the browsers.











 


 



post.php source code:


Example

header set access-control-allow-origin multiple domains | cross domain ajax request,cross domain ajax request jquery | no access control allow origin header is present jquery ajax origin

Leave a Comment