@rollin
To post to a custom endpoint with Ember.js, you can use the $.ajax
method provided by jQuery. Here's an example of how you can make a POST request to a custom endpoint:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import Service from '@ember/service'; import { inject as service } from '@ember/service'; import { computed } from '@ember/object'; export default Service.extend({ ajax: service(), postData(data) { return this.get('ajax').request('/your-custom-endpoint', { method: 'POST', data: data }); }, }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import Controller from '@ember/controller'; import { inject as service } from '@ember/service'; export default Controller.extend({ customEndpoint: service(), actions: { async postData(data) { try { await this.get('customEndpoint').postData(data); console.log('POST request successful.'); } catch (error) { console.error('POST request failed:', error); } }, }, }); |
1
|
<button {{action "postData" someData}}>Post Data</button> |
That's it! You have now posted data to a custom endpoint in Ember.js using the $.ajax
method.