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…).
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
// Using Error Javascript File request to the server $.ajax({ type: "GET", web_url: "https://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("<b>Example of cors: </b>"+People_list_data+"<b><br> Listing data view: </b>"+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 https://infinityknow.com/retrieve_data.php/v1/login. (Reason: CORS header 'Access-Control-Allow-Origin' missing). }
Server side code Solution
There just put in https://infinityknow.com/retrieve_data.php file
Solution No 1 <?php // all permission include this Headers header('Access-Control-Allow-Origin: *'); ------- ------ ------- your code here - respnse code -------- ?> alternative Solution No 2 <?php // include this Headers with content-type header('content-type: application/json; charset=utf-8'); header("access-control-allow-origin: *"); ?> alternative Solution No 3 <?php // two include this Headers header('Content-type: text/html'); header('Access-Control-Allow-Origin: *'); ?>
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
E-junkie: Sell digital downloads online
E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!
Also see:
<IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" </IfModule> or <IfModule mod_headers.c> Header set Access-Control-Allow-Origin https://infinityknow.com Header set Access-Control-Allow-Credentials true </IfModule>
How to Enable Access-Control-Allow-Origin chrome
please click this link and add the cors chrome extensions and after than send request.
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
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:
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