on 2024 May 22 7:54 AM
I have a function which create an entry in backend when an button ( save button ) is pressed.
Code for creating entry
var oModel = this.getModel('action');
oModel.create(path, body, {
success: this._onSuccess.bind(this), //How to pass response along with the bind function
error: this._onError.bind(this)
});
_onSuccess: function (response) {
// Response is not having any headers
//Show some success message
},
Instead of directly calling the function, I have binded the _onSuccess function to oModel.create's success handler. From the backend I am sending some header parameters along the (POST) response, which I need to access inside the _onSuccess message and display. When I directly include the function in success handler, I am able to see the response, but not sure how send it along the bind parameter
This is working
callCreate: function (path, body) {
var oModel = this.getModel('action');
oModel.create(path, body, {
success: function (data, response) {
//I am able to get the response headers here
},
error: this._onError.bind(this)
});
},
Request clarification before answering.
Hi, you just need to add an additional parameter to your _onSuccess function definition. Modify your _onSuccess function definition on line 6 to following:
var oModel = this.getModel('action');
oModel.create(path, body, {
success: this._onSuccess.bind(this), //How to pass response along with the bind function
error: this._onError.bind(this)
});
_onSuccess: function (data, response) {
// Response is not having any headers
//Show some success message
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
53 | |
8 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.