Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

spring rest api cors error in react app

add below line of code in fetch

  export function getData(endpoint = '/', request = {}) {
    let url = endpoint;
    let req = Object.assign(
      {
        headers: {
          Accept: 'application/json',
          'Content-Type': 'application/json',
          'Access-Control-Allow-Origin': '*',
        },
      },
      request
    );
    console.log('url,req', url, req);
    return fetch(url, req).then(handleResponse).catch(handleErrors);
  }
And Add below line below Rest Controller class

@RestController
@CrossOrigin(origins = "*", allowedHeaders = "*")
class TestController{}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Nuxt JS Adding script tag to particular page 
Javascript :: Error: `createStackNavigator()` has been moved to `react-navigation-stack`. 
Javascript :: event.target parent 
Javascript :: js check if dom element exists 
Javascript :: momeny day in range 
Javascript :: componentdidupdate in hooks 
Javascript :: js dynamic import js 
Javascript :: splidejs example 
Javascript :: how to show bootstrap 5 modal using jquery 
Javascript :: angular access form control value 
Javascript :: nodejs on exit event 
Javascript :: Unexpected token a in JSON at position 
Javascript :: seconds to degrees 
Javascript :: snap to grid 
Javascript :: convertir seconde 
Javascript :: remove undefined from javascript array map 
Javascript :: nuxt js if is client 
Javascript :: how to numeric value is after point 2 values in javascript 
Javascript :: tab active check 
Javascript :: redux saga delay 
Javascript :: swapping elements in an array 
Javascript :: refresh page on div click 
Javascript :: jquery change select option text 
Javascript :: toggle in react 
Javascript :: javascript replace all 
Javascript :: how to make a rectangle in javascript 
Javascript :: ngchange angular 8 
Javascript :: javascript change dataset value 
Javascript :: javascript add days to date 
Javascript :: is_int js 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =