jquery - Passing variable from Ajax Call into the Success Function -
i have code takes user input, incorporates ajax call url, retrieves data based on input.
the retrieved data in json format, , want access part of json object using user's original input.
for example:
user input: example_name
ajax url: www.something.com/api/example_name?api_key=12345
upon returning object:
i want access: object.example_name.id
i having difficulties passing variable 'example_name
' original ajax call success function.
here code:
function getsummonerid(n) { console.log("check function..."); $.ajax({ datatype: "json", type: 'get', url: 'https://url_here/' + n + '?api_key=12345', success: function (json, n) { console.log(json); console.log(n); //this logs "success" summonerid = json[n].id; console.log(summonerid); getscore(summonerid); //send function } }); }
i getting error of sort:
typeerror: json[n] undefined
there other threads asking question, couldn't find pass 'n' original call success function.
thanks!
i ended adding variable function called fname
, , set equal "n
" passed it.
i used json[fname].id
access value.
Comments
Post a Comment