Question

API Calls

  • 21 August 2023
  • 6 replies
  • 42 views

I get CORS Policy error each time I try to make a request with the JavaScript fetch API to any of the sandbox endpoints but it works on the sandbox page


6 replies

Userlevel 2

Hello.
To solve the CORS error on localhost Devt, kindly follow these steps.
1.create a folder , rename it to MoMoCORS

2.Create a file in the folder, rename it to solvecors.bat

  1. paste these lines of code, ensure the you replace the path to where your chrome exe launcher is.
  2.  

    cd C:\Program Files\Google\Chrome\Applicationthe line of code syntax below disables web security on the chrome tab when launched
    Chrome.exe –user-data-dir = "C:\Users\cznki\Documents\my\data(the directory of the batch file)" --disable-web-security.

    5. Double click on the batch file you created (solvecors.bat) to launch the chrome browser. Paste the localhost URL.

    Thank me later by subscribing to youtube.com/crankluga
Userlevel 2

My previous submission is being reviewed and will be availed to you soon. 
Not sure why it needed to be reviewed, maybe because i added code. But here you go.
Follow the steps below.
 

  1. Create a folder on your localhost director and rename it CORS, inside create notepad file and open it and save as disablecors.bat
  2. Type the following statement to launch your chrome browser, it should link up to your chrome application directory

//////Dont include this line

cd C:\Program Files\Google\Chrome\Application
the line of code syntax below disables web security on the chrome tab when launched

Chrome.exe –user-data-dir = "C:\Users\cznki\Documents\my\data(the directory of the batch file)" --disable-web-security.
//////Dont include this line

  1. Double click on the batch file to launch the chrome browser. Paste the localhost URL.
Userlevel 2

I have submitted a solution for you but it is being reviewed by the modorator, kindly be patient, it will be availed to you after review.

Userlevel 3
Badge

I have submitted a solution for you but it is being reviewed by the modorator, kindly be patient, it will be availed to you after review.

 

Userlevel 1

I have submitted a solution for you but it is being reviewed by the modorator, kindly be patient, it will be availed to you after review.

 

What happens incase I am not using Chrome

Userlevel 2

Sorry, you have to, no need to be rigid if that is the available working solution at the moment.
The CORS is security by your browser as a result of your localhost blocking the response from MoMo.

Reply