How to Enable Cross Origin Resource Sharing (CORS) for Sharing Resource Using Apache Servers, PHP and Jquery

Method 1 of 2:

Client Side Domain

  1. This involves sending a request for some resource
  1. How to Enable Cross Origin Resource Sharing (CORS) for Sharing Resource Using Apache Servers, PHP and Jquery Picture 1
    Open the HTML file present on the client side in which you are sending resource request. As shown, the client is sending request to server side for getting customer's record with ID as '145'.
  2. How to Enable Cross Origin Resource Sharing (CORS) for Sharing Resource Using Apache Servers, PHP and Jquery Picture 2
    Mention the IP address of the server side domain and complete path of the file that need to be accessed. As shown, the file demo.php which needs to be accessed is present on the Apache sever (occupying port 80) of the server side domain. The server side domain has an IP address of 192.148.0.108.
  3. How to Enable Cross Origin Resource Sharing (CORS) for Sharing Resource Using Apache Servers, PHP and Jquery Picture 3
    Launch the request using your Apache server by putting the URL localhost/CORS-UsingJquery/sub2.html on the web browser's address bar. As the path indicates, the requesting client side file sub2.html is present inside a folder named as CORS-UsingJquery. If the access headers are properly set on the server side, then the record of the customer with ID as '145' will be successfully displayed.
Method 2 of 2:

Server Side Domain

  1. This involves generating a response to a resource request.
  1. How to Enable Cross Origin Resource Sharing (CORS) for Sharing Resource Using Apache Servers, PHP and Jquery Picture 4
    Open the PHP file present on the server side in which you intend to send the response back to the client side.
    1. Set and customize appropriate headers to allow client's access to file demo2php. The statement header ('Access-Control-Allow-Origin: *'); allows access to every domain as indicated by asterisk (*). You can also specify the IP address of some specific domain to grant access only to that domain.
  2. How to Enable Cross Origin Resource Sharing (CORS) for Sharing Resource Using Apache Servers, PHP and Jquery Picture 5
    If the headers are specified correctly, then resource access is granted successfully to client side domain.
4.5 ★ | 2 Vote

May be interested

  • Attributes in jQueryAttributes in jQuery
    some of the most basic components, we can manipulate dom elements, are properties and attributes assigned to those elements.
  • Basic about jQueryBasic about jQuery
    this article will explain the basic concepts commonly used in jquery such as: string (string), number (number), boolean, array (array), function, parameter, context, ...
  • How to Use jQuery on Your WebsiteHow to Use jQuery on Your Website
    jquery is the most popular javascript language by far, used by many popular websites across the internet. however, since it is a library, it is not a part of unaltered javascript. how, then, can you use jquery on your website? the process...
  • jQuery AjaxjQuery Ajax
    ajax stands for asynchronous javascript and xml and this technology helps us to download data from the server without refreshing the browser.
  • Compare Nginx and ApacheCompare Nginx and Apache
    the truth is that both apache and nginx are at the core of the complete web stack (lamp as well as lemp) and the final choice depends on the needs of each individual.
  • Download XAMPP 8.0.2: Free local Web serverDownload XAMPP 8.0.2: Free local Web server
    xampp was created by apache friends. it stands for cross-platform (x), apache, mariadb (mysql), php and perl.
  • Critical error on Apache Struts2 allows hackers to take over the web serverCritical error on Apache Struts2 allows hackers to take over the web server
    new researchers have discovered a remote code execution flaw in the apache struts open source web application framework, allowing an attacker to run malicious code on the server.
  • MSI presents the laptop to play 'dinosaur' GE70 Apache ProMSI presents the laptop to play 'dinosaur' GE70 Apache Pro
    according to information from the notebookcheck page, msi has just officially unveiled a giant ge70 apache pro laptop. this product is equipped with core i7 haswell processor, 17.3 inch full hd screen, 12 gb ram and 2 gb of gddr5 discrete geforce gtx 765m graphics card.
  • Fsutil resource command in WindowsFsutil resource command in Windows
    the fsutil resource command creates a secondary transactional resource manager, starts or stops transactional resource manager, or displays information about transactional resource manager.
  • Instructions for creating Origin accountInstructions for creating Origin account
    with origin account, you can buy and receive free titles from ea