Sails version: 1.0.2
Node version: 8.10.0
NPM version: 6.4.1
DB adapter name: sails-mongo
DB adapter version: sails-mongo
Operating system: Mac OS
Hello,
I want to get an object from an action, which is called by an ajax form component.
Steps to reproduce.
create a ajax form where you passing values for a model (eg. title and description for a post)
After handling the submitting form let pass the data to a action
In the action you will safe the given data to the MongoDB and fetch that created data with .fetch()
You pass the fetched data to exits.success(fetchedData)
Try to get the data in the submittedForm function in the xxxx.page.js
I am not able to get the data. I logged the ajax-form.components.js. In line 398, we emit the result (the result should have our data, in my case it is the fact) but after that, the result is gone.
Maybe I understand it wrong, obviously I do things wrong.
If you need more info, let me know.
Hi @bleakhead! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:
As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!
*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]
Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again.
*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]
Ok, fixed!
Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again.
*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]
To get data back from the back end using an ajax form, you need to include a 'submitted' function. In your html:
<ajax-form action="nameOfAction" @submitted="submittedAjaxForm" ... >
This function runs only if the action returns a success response. In the page script (front-end javascript file that includes a .page in the file name), you will define this function and what you want to do with the data:
submittedAjaxForm: async function (responseData) {
console.log(responseData);
}
Hi @Ghost I hope @streleck commit got you moving in the right direction. To tidy up the Sails issues we are closing issues that are older or resolved. Please feel free to create another issue if the need arises.
Most helpful comment
To get data back from the back end using an ajax form, you need to include a 'submitted' function. In your html:
<ajax-form action="nameOfAction" @submitted="submittedAjaxForm" ... >This function runs only if the action returns a success response. In the page script (front-end javascript file that includes a .page in the file name), you will define this function and what you want to do with the data:
submittedAjaxForm: async function (responseData) { console.log(responseData); }