H
H
heducose2017-07-19 16:21:56
Node.js
heducose, 2017-07-19 16:21:56

How to POST from another domain?

Can't POST from frontend app to server.
added

const cors = require('cors')
app.use(cors())

but still POST fails.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
myspace, 2017-07-19
@heducose

on server:

let corsOptions = {
    origin: 'http://front.xxx.ru',
    optionsSuccessStatus: 200, 
    credentials: true
};

app.use(cors(corsOptions));

and on the
angularjs 1.x purejs client
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.open('POST', 'http://xxx.ru', true)

jQuery
$.ajax({
   ///
    crossDomain: true,
  ///
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question