on 2016 Jun 13 3:24 PM
Hi experts ,
I developed here one oData Get call that is working fine. But form the success function i just need to call one more function there .
So how to call the other function from the success function.
Plz correct me if i may did wrong anywhere. And send me your guidelines.
I attached my coding here .
press :function () {
var surl = "service url here ";
OData.request
({
requestUri:surl,
method: "GET",
headers:
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"DataServiceVersion": "2.0",
"X-CSRF-Token":"Fetch"
}
},
function(data, response) { // onSuccess function called when everything is ok
this.applySearch(); // if i call the function like this i am getting error like this is not a function like that
}
},
applySearh : function () {
}
Thanks and Regards ,
Damian .A
Damian,
that is because this is out of scope... you can have
var self = this;
right before your ajax call..
then inside the success function:
self.applySearch(); // instead of this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please mark this Discussion with a Correct Answer (closes, but does not lock the Discussion) and Helpful Answer where appropriate. See http://scn.sap.com/community/support/blog/2013/04/03/how-to-close-a-discussion-and-why Even if you discovered the solution without any outside contributions, it helps others to understand what the solution turned out to be.
Do not use Assumed Answered as it confuses anyone looking for the specific answer. If you dig into the Getting Started link (top right of each SCN page), you are only instructed to mark Helpful or Correct Answers to Discussion responses.
Thanks, Mike (Moderator)
SAP Technology RIG
You could set a var to the context of press
var self = this;
and then in you success function
self.applySearch()
There's also other ways such as jQuery.proxy to do the same.
Regards,
Jamie
SAP - Technology RIG
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When you call a function from inside another you need to refer to it with the "this" keyword.
this refers to the javascript file you are inside of.
In your instance you are on the third level.
So you need to set "this inside your main fuction as something else.
Take a look below this is how your code will change (the bold parts)
press :function () {
that = this;
var surl = "service url here ";
OData.request
({
requestUri:surl,
method: "GET",
headers:
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"DataServiceVersion": "2.0",
"X-CSRF-Token":"Fetch"
}
},
function(data, response) { // onSuccess function called when everything is ok
that.applySearch(); // if i call the function like this i am getting error like this is not a function like that
}
},
applySearh : function () {
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
62 | |
12 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.