Return Value
3 posters
Page 1 of 1
Return Value
- Code:
$(function(){
var str = ABC(ID); // str = strReturn
});
function ABC(ID) {
$.get('/u' + ID + '/profile?mode=editprofile&page_profil=friendsfoes', function (e) {
var strReturn;
// do somthing here and strReturn has some value
// return strReturn
// e.g strReturn = "123"
strReturn = "123";
return(strReturn); // does not work
})
}
How do I get the return value ??
Last edited by TamDonCo on September 16th 2016, 3:46 pm; edited 1 time in total
Re: Return Value
It would help if you exactly explain what this script does?
Lost Founder's Password |Forum's Utilities |Report a Forum |General Rules |FAQ |Tricks & Tips
You need one post to send a PM.
You need one post to send a PM.
When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
Re: Return Value
- Code:
function ABC(ID) {
$.get('/u' + ID + '/profile?mode=editprofile&page_profil=friendsfoes', function (e) {
var strReturn = $('.panel:eq(4)', e).html();
typeof strReturn !== "undefined" && (document.body.insertAdjacentHTML('afterbegin', strReturn));
})
}
if you want some element of friend page, you need set it in a var search in ajax dom and you can insert this element werever you want
with
|
Ch@lo Valdez- Forumember
- Posts : 138
Reputation : 50
Language : spanish
Re: Return Value
What kind of data you try to return?
Ch@lo Valdez- Forumember
- Posts : 138
Reputation : 50
Language : spanish
Re: Return Value
TamDonCo wrote:Thanks Ch@lo Valdez
I try my own ID first but it returns "undefined"
just a string, I test
- Code:
var str = ABC(ID);
it returns "undefined"
Re: Return Value
what kind of string? is important you write here your complete idea, otherwise no one can help
Ch@lo Valdez- Forumember
- Posts : 138
Reputation : 50
Language : spanish
Re: Return Value
Ch@lo Valdez wrote:what kind of string? is important you write here your complete idea, otherwise no one can help
just get the foes list from current login user , not others
the function ABC get the foes list , I can do that part and return that value back to main function
Re: Return Value
This is my sample , just ignore line 18-65 , only string manipulation, the final string on line 67 and good but failed to return value to main function on line 70
- Code:
$(function(){
// guest login, just exit
if (! (_userdata.session_logged_in)) return;
var uID = _userdata.user_id ;
var foesstring = getFoesList(uID);
window.console && console.log("!" + foesstring);
});
function getFoesList(uID) {
$.get('/u' + uID + '/profile?mode=editprofile&page_profil=friendsfoes', function (e) {
var n1, n2;
n2 = e.indexOf('>Foes list<');
n1 = e.indexOf('>Friends list<');
var strFoes = e.substr(n2);
var strFriends = e.substr(n1, n2 - n1);
var n = 0;
var nEnd = 0;
var Friends = "";
var FriendsID = "";
while (n >= 0) {
n= strFriends.indexOf('friends-foes-list');
if (n >= 0) {
strFriends = strFriends.substr(n+30);
nEnd = strFriends.indexOf('">') ;
FriendsID = FriendsID + "," + strFriends.substr(0,nEnd);
strFriends = strFriends.substr(nEnd+2);
nEnd = strFriends.indexOf('</a>') ;
Friends = Friends + "," + strFriends.substr(0,nEnd);
}
}
FriendsID = FriendsID.substr(1);
Friends = Friends.substr(1);
n = 0 ;
nEnd = 0;
var Foes = "";
var FoesID = "";
while (n >= 0) {
n= strFoes.indexOf('friends-foes-list');
if (n >= 0) {
strFoes = strFoes.substr(n+30);
nEnd = strFoes.indexOf('">') ;
FoesID = FoesID + "," + strFoes.substr(0,nEnd);
strFoes= strFoes.substr(nEnd+2);
nEnd = strFoes.indexOf('</a>') ;
Foes = Foes + "," + strFoes.substr(0,nEnd);
}
}
FoesID = FoesID.substr(1);
Foes = Foes.substr(1);
// It 's OK until here, get all foes ID
window.console && console.log(FoesID);
// Return failed and get undefined
return FoesID;
});
}
Re: Return Value
ok try this i think inside of get ajax you can't return string or maybe i dont know how lol
but look this:
but look this:
- Code:
$(function(){
// guest login, just exit
if (! (_userdata.session_logged_in)) return;
var uID = _userdata.user_id ;
var foesstring = getFoesList(uID);
window.console && console.log("!" + foesstring);
});
function getFoesList(uID) {
$.get('/u' + uID + '/profile?mode=editprofile&page_profil=friendsfoes', function (e) {
var n1, n2;
n2 = e.indexOf('>Foes list<');
n1 = e.indexOf('>Friends list<');
var strFoes = e.substr(n2);
var strFriends = e.substr(n1, n2 - n1);
var n = 0;
var nEnd = 0;
var Friends = "";
var FriendsID = "";
while (n >= 0) {
n= strFriends.indexOf('friends-foes-list');
if (n >= 0) {
strFriends = strFriends.substr(n+30);
nEnd = strFriends.indexOf('">') ;
FriendsID = FriendsID + "," + strFriends.substr(0,nEnd);
strFriends = strFriends.substr(nEnd+2);
nEnd = strFriends.indexOf('</a>') ;
Friends = Friends + "," + strFriends.substr(0,nEnd);
}
}
FriendsID = FriendsID.substr(1);
Friends = Friends.substr(1);
n = 0 ;
nEnd = 0;
var Foes = "";
var FoesID = "";
while (n >= 0) {
n= strFoes.indexOf('friends-foes-list');
if (n >= 0) {
strFoes = strFoes.substr(n+30);
nEnd = strFoes.indexOf('">') ;
FoesID = FoesID + "," + strFoes.substr(0,nEnd);
strFoes= strFoes.substr(nEnd+2);
nEnd = strFoes.indexOf('</a>') ;
Foes = Foes + "," + strFoes.substr(0,nEnd);
}
}
FoesID = FoesID.substr(1);
Foes = Foes.substr(1);
// It 's OK until here, get all foes ID
window.console && console.log(FoesID);
// inside of $.get function maybe is better storage the data in cookie or window.storage and call in another function, just try it
my_setcookie('friendsid'+uID, FoesID);
return_friends(uID)
});
}
function return_friends(c){
return my_setcookie('friendsid'+c);
}
//use return_friends(id) example: document.body.innerHTML = return_friends(_userdata.user_id)
Ch@lo Valdez- Forumember
- Posts : 138
Reputation : 50
Language : spanish
Re: Return Value
mmm or just use a universal variable
and return string
or this way:
but still use
to return string
- Code:
$(function(){
// guest login, just exit
if (! (_userdata.session_logged_in)) return;
var uID = _userdata.user_id ;
var foesstring = getFoesList(uID);
window.console && console.log("!" + foesstring);
});
function getFoesList(uID) {
$.get('/u' + uID + '/profile?mode=editprofile&page_profil=friendsfoes', function (e) {
var n1, n2;
n2 = e.indexOf('>Foes list<');
n1 = e.indexOf('>Friends list<');
var strFoes = e.substr(n2);
var strFriends = e.substr(n1, n2 - n1);
var n = 0;
var nEnd = 0;
var Friends = "";
var FriendsID = "";
while (n >= 0) {
n= strFriends.indexOf('friends-foes-list');
if (n >= 0) {
strFriends = strFriends.substr(n+30);
nEnd = strFriends.indexOf('">') ;
FriendsID = FriendsID + "," + strFriends.substr(0,nEnd);
strFriends = strFriends.substr(nEnd+2);
nEnd = strFriends.indexOf('</a>') ;
Friends = Friends + "," + strFriends.substr(0,nEnd);
}
}
FriendsID = FriendsID.substr(1);
Friends = Friends.substr(1);
n = 0 ;
nEnd = 0;
var Foes = "";
var FoesID = "";
while (n >= 0) {
n= strFoes.indexOf('friends-foes-list');
if (n >= 0) {
strFoes = strFoes.substr(n+30);
nEnd = strFoes.indexOf('">') ;
FoesID = FoesID + "," + strFoes.substr(0,nEnd);
strFoes= strFoes.substr(nEnd+2);
nEnd = strFoes.indexOf('</a>') ;
Foes = Foes + "," + strFoes.substr(0,nEnd);
}
}
FoesID = FoesID.substr(1);
Foes = Foes.substr(1);
// It 's OK until here, get all foes ID
window.console && console.log(FoesID);
foesID = FoesID;
});
}
|
or this way:
- Code:
$(function(){
// guest login, just exit
if (! (_userdata.session_logged_in)) return;
var uID = _userdata.user_id ;
var foesstring = getFoesList(uID);
window.console && console.log("!" + foesstring);
});
function getFoesList(uID) {
var foesID; // <----- new var
$.get('/u' + uID + '/profile?mode=editprofile&page_profil=friendsfoes', function (e) {
var n1, n2;
n2 = e.indexOf('>Foes list<');
n1 = e.indexOf('>Friends list<');
var strFoes = e.substr(n2);
var strFriends = e.substr(n1, n2 - n1);
var n = 0;
var nEnd = 0;
var Friends = "";
var FriendsID = "";
while (n >= 0) {
n= strFriends.indexOf('friends-foes-list');
if (n >= 0) {
strFriends = strFriends.substr(n+30);
nEnd = strFriends.indexOf('">') ;
FriendsID = FriendsID + "," + strFriends.substr(0,nEnd);
strFriends = strFriends.substr(nEnd+2);
nEnd = strFriends.indexOf('</a>') ;
Friends = Friends + "," + strFriends.substr(0,nEnd);
}
}
FriendsID = FriendsID.substr(1);
Friends = Friends.substr(1);
n = 0 ;
nEnd = 0;
var Foes = "";
var FoesID = "";
while (n >= 0) {
n= strFoes.indexOf('friends-foes-list');
if (n >= 0) {
strFoes = strFoes.substr(n+30);
nEnd = strFoes.indexOf('">') ;
FoesID = FoesID + "," + strFoes.substr(0,nEnd);
strFoes= strFoes.substr(nEnd+2);
nEnd = strFoes.indexOf('</a>') ;
Foes = Foes + "," + strFoes.substr(0,nEnd);
}
}
FoesID = FoesID.substr(1);
Foes = Foes.substr(1);
foesID = FoesID;
});
return foesID //return after ajax request
}
but still use
|
Ch@lo Valdez- Forumember
- Posts : 138
Reputation : 50
Language : spanish
Re: Return Value
ok after read a lot of pages this is how, i think
call with
$.get is a shorthand of $.ajax, but by default asinc mode is true, and we need asinc in false mode
- Code:
function getFoesList(uID) {
var B, A = $.ajax({
type: "GET",
url: '/u' + uID + '/profile?mode=editprofile&page_profil=friendsfoes',
async: false,
cache: false,
type: "get",
dataType: "text",
success: function (response, status, xhr) {
if (xhr.status == 200) {
var n2 = response.indexOf('>Foes list<'),
n1 = response.indexOf('>Friends list<'),
strFoes = response.substr(n2),
strFriends = response.substr(n1, n2 - n1),
n = 0,
nEnd = 0,
Friends = "",
FriendsID = "";
while (n >= 0) {
n = strFriends.indexOf('friends-foes-list');
if (n >= 0) {
strFriends = strFriends.substr(n + 30);
nEnd = strFriends.indexOf('">');
FriendsID = FriendsID + "," + strFriends.substr(0, nEnd);
strFriends = strFriends.substr(nEnd + 2);
nEnd = strFriends.indexOf('</a>');
Friends = Friends + "," + strFriends.substr(0, nEnd);
}
}
FriendsID = FriendsID.substr(1);
Friends = Friends.substr(1);
n = 0;
nEnd = 0;
var Foes = "";
var FoesID = "";
while (n >= 0) {
n = strFoes.indexOf('friends-foes-list');
if (n >= 0) {
strFoes = strFoes.substr(n + 30);
nEnd = strFoes.indexOf('">');
FoesID = FoesID + "," + strFoes.substr(0, nEnd);
strFoes = strFoes.substr(nEnd + 2);
nEnd = strFoes.indexOf('</a>');
Foes = Foes + "," + strFoes.substr(0, nEnd);
}
}
FoesID = FoesID.substr(1);
Foes = Foes.substr(1);
B = FriendsID; // or FoesID
}
}
});
return B
}
call with
|
$.get is a shorthand of $.ajax, but by default asinc mode is true, and we need asinc in false mode
Ch@lo Valdez- Forumember
- Posts : 138
Reputation : 50
Language : spanish
Re: Return Value
Problem solved & topic archived.
|
Lost Founder's Password |Forum's Utilities |Report a Forum |General Rules |FAQ |Tricks & Tips
You need one post to send a PM.
You need one post to send a PM.
When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
Similar topics
» AForum
» Return To Top Code
» Smileys Return
» Need some help adding a "return to top"-button...
» Can I return servimg pictures on my forum
» Return To Top Code
» Smileys Return
» Need some help adding a "return to top"-button...
» Can I return servimg pictures on my forum
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum