When i send a post method it will change automatically into options

I am new to ionic . I need to send post request for login and I need to receive success message…When I send a post request it will change automatically into options. Here I have attached code for login module.

let headers= new Headers();   
    let body = {    
.map(res => res.json())        
.do(data => {        console.log(data);        })    
 .subscribe(data =>{          

ionic.config.json: -

"name": "ionic2-app-base",  
"app_id": "",  
"type": "ionic-angular",  
"proxies" : [   
 "path": "/login",      
"proxyUrl": ""   

Server login.py console result - - [27/May/2017 19:41:20] "OPTIONS /login HTTP/1.1" 200 -

ionic console Error:

19:41:20.167 Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at (Reason: CORS header 'Access-Control-Allow-Origin' missing).1 (unknown)

19:41:20.220 failed1 main.js:45090:13

19:41:20.087 Object { _isScalar: false, _subscribe: XHRConnection/this.response<() }1 main.js:45081:9

I hope you can understand my problem. Please tell me a solution . Thanks in advance

1 Like

This normal and called a “preflight request”: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests Your browser has decided this is a complex request and requires a security check (CORS), which is this OPTIONS request.

Just make your server respond correctly and you are all good.

1 Like

Thank you @Sujan12 . And I need one more help. Now server works correctly. But When I send data to server. Server shows the data is none. Can you explain me how to send a data.

21:31:20.880 Object { _body: error, status: 0, ok: false, statusText: "", headers: Object, type: 3, url: null }1 main.js:45088:13

Server console

None - - [28/May/2017 21:31:20] "OPTIONS /login HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/dinesh/.local/lib/python3.4/site-packages/flask/app.py", line 1994, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/dinesh/.local/lib/python3.4/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/home/dinesh/.local/lib/python3.4/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/dinesh/.local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/dinesh/.local/lib/python3.4/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/dinesh/.local/lib/python3.4/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/dinesh/.local/lib/python3.4/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/dinesh/.local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/dinesh/.local/lib/python3.4/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/dinesh/.local/lib/python3.4/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/dinesh/Intern/App.py", line 53, in login
    if result.Password == Password and result.Department == 'HR':
AttributeError: 'NoneType' object has no attribute 'Password'

1 Like

I have the same problem, did you managed to solve it?