Hi!
I am trying to call a POST method from a Vue.js frontend. My backend is
web2py serving a REST API:
@request.restful()
> @cors_allow
> def save_transaction():
> response.view = 'generic.json'
>
> def POST(**data):
> # Creating the parent transaction
>
> parent = {'parent_transaction' : None,
> 'transaction_date': '01/01/2019',
> 'transaction_label' : 'label',
> 'transaction_type' : data['transaction_type'],
> 'treatment': data['selected_treatment'],
> 'transaction_value': data['total_value'],
> 'paid': data['allpaid'],
> 'payment_method': None
> }
>
> return db.transactions.validate_and_insert(**parent)
>
> return locals()
>
My DB is:
db.define_table('transactions',
> Field('parent_transaction', type='reference transactions',
> requires=IS_EMPTY_OR(IS_IN_DB(db, 'transactions.id',
> '%(transaction_label)s'))),
> Field('transaction_date', 'date',
> requires=IS_DATE(format='%d/%m/%Y',error_message='Coloque uma data no
> formato DD/MM/AAAA')),
> Field('transaction_label', 'string'),
> Field('transaction_type', 'string',
> requires=IS_IN_SET(['Receita','Despesa'])),
> Field('treatment', type='reference contact_treatment',
> requires=IS_EMPTY_OR(IS_IN_DB(db, 'contact_treatment.id',
> '%(description)s'))),
> Field('description', 'string',
> requires=IS_NOT_EMPTY(error_message='Preencha com uma descrição')),
> Field('transaction_by', 'reference contacts',
> requires=IS_EMPTY_OR(IS_IN_DB(db, 'contacts.id', '%(name)s',))),
> Field('transaction_value', 'float',
> requires=IS_FLOAT_IN_RANGE(None, None, dot=","), default=0),
> Field('paid', 'boolean', default=False),
> Field('payment_method', type='reference payment_methods',
> requires=IS_EMPTY_OR(IS_IN_DB(db, 'payment_methods.id', '%(name)s'))),
> )
>
This is the Data sent:
> {'parent_transaction': None, 'transaction_date': '01/01/2019',
> 'transaction_label': 'label', 'transaction_type': 'Receita', 'treatment':
> 1, 'transaction_value': 250, 'paid': False, 'payment_method': None}
>
This is the response:
> 1. config: {url: "
> http://127.0.0.1:8000/controle7030/product/save_transaction", method:
> "post", data:
>
> "{"total_value":250,"costs":[[{"id":1,"product":1,"…85","total_cost":66,"transaction_type":"Receita"}"
> , headers: {…}, transformRequest: Array(1), …}
> 2. data: "iderrors"
> 3. headers: {pragma: "no-cache", content-type: "text/html;
> charset=utf-8", cache-control: "no-store, no-cache, must-revalidate,
> post-check=0, pre-check=0", expires: "Wed, 17 Jul 2019 14:35:41 GMT"}
> 4. request: XMLHttpRequest {onreadystatechange: ƒ, readyState: 4,
> timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
> 5. status: 200
> 6. statusText: "OK"
> 7. __proto__: Object
>
>
Any idea what is wrong? What does mean "iderrors"?
Thank you!
Tito
--
Linux User #387870
.........____
.... _/_õ|__|
..º[ .-.___.-._| . . . .
.__( o)__( o).:_______
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/CAL67CHGkE3PscxpbDrcGBHMJK-jwSFJOon2NjCVE3EKe08q5gw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.