Angular Access-Control-Allow-Origin PHP htaccess

Angular Access-Control-Allow-Origin PHP htaccess

Today, We want to share with you Angular Access-Control-Allow-Origin PHP htaccess.
In this post we will show you Access-Control-Allow-Origin solution – Angularjs PHP Javascript and htaccess, hear for Access-Control-Allow-Origin solution – Angularjs PHP Javascript we will give you demo and example for implement.
In this post, we will learn about Angular .htaccess – htaccess Access-Control-Allow-Origin with an example.

Access-Control-Allow-Origin stands for other name is CORS (Cross-Origin Resource Sharing) header.

The Access-Control-Allow-Origin Resource Sharing standard works by adding new HTTP headers mean request that allow servers(permitted) to describe the set of origins(all) that are permitted to read(data read) that information using a web browser(chrome,mozila…).

READ :  Simple Pagination With AngularJS and JSON using PHP

It’s one type of Read permitted.

Solution for PHP – Using htaccess Access-Control-Allow-Origin

Error code or Angularjs,Javascript File Request in PHP

[php]
// Using Error Javascript File request to the server

$.ajax({
type: “GET”,
web_url: “http://infinityknow.com/retrieve_data.php”,
data: “post_id=” + s_id + “&url_data=” + web_url,
dataType: ‘json’,
cache: false,
success: function(data)
{
var People_list_data = data[1];
var data_list = data[2];
$(‘#maindivid’).html(“Example of cors: “+People_list_data+”
Listing data view:
“+data_list);

}
});

// Using Error Angularjs File request to the server

$htttp.get(url).success()

{
error genrated
//Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://infinityknow.com/retrieve_data.php/v1/login. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
}
[/php]

Server side code Solution

There just put in http://infinityknow.com/retrieve_data.php file

READ :  MVC Framework PHP Tutorial with Example

[php]
Solution No 1

alternative

Solution No 2

alternative

Solution No 3


[/php]

Solution for htaccess – Using htaccess Access-Control-Allow-Origin

Go to Root Folder and First of all take a backup in htaccess file and past this code in .htaccessfile

[php]


Header set Access-Control-Allow-Origin “*”

or


Header set Access-Control-Allow-Origin http://infinityknow.com
Header set Access-Control-Allow-Credentials true

[/php]

How to Enable Access-Control-Allow-Origin chrome

please click this link and add the cors chrome extensions and after than send request.

[php]
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
[/php]

A Simple requests of client side to server side send Request

A simple Access-Control-Allow-Origin or cross-site request is one that meets all the List of following conditions:

READ :  CCAvenue Payment Gateway Integration using PHP

The only allowed methods are:

Using GET Method
Using HEAD Method
Using POST Method

Apart from the headers(CORS) set automatically by the user agent (e.g. Connection, Content-Type,User-Agent, etc.), the only cors(headers) which are allowed to be manually header type set are below:

Accept
Accept-Language
Content-Language
Content-Type

There are list of allow the Content-Type header are:

application/x-www-form-urlencoded
multipart/form-data
text/plain

Leave a Comment