I send a post to the server to create a new table entry in my database. Once the table entry is created I have the server respond with the id of the table entry. In the chrome developer tools I can see the response as just a singular number (i.e. if its the fifth entry in the table the server response is just 5). How do I store this information using javascript/YUI to be used later? Do I have to do something with the Y.io on: success function?
EDIT:
Y.io('/sessionsimulator/sessioncreate/', {
method: 'POST',
data: jdtoldstring,
headers: {
'Content-Type': 'application/json'
},
on: {
success: buildtable()
}
});
this is the code that posts the date/time and creates a session id. I can view the sqlite table afterwards and see that the session is created exactly how I wanted. the success function buildtable is the code that is called to generate the simulated data. within buildtable() i have a global variable that I am trying to set called sess_is
sess_id = Y.JSON.parse.responseText;
that statement lies within buildtable(), but when the table is created, the column that is filled with sess_id the variable is "undefined."
I can see in the developer tools the response to the url call /createsession is a number, I am just trying to pick that number and store it in sess_id variable.
If the response is just a number, you can access it from response.responseText
in your IO success callback. It's a string, so you need to parse it as a number:
Y.io(url, {
//...
on: {
success: function (requestId, response) {
var id = parseInt(response.responseText, 10);
// do something with the id
}
}
});
It's usually a good idea to send JSON from the server and parse it in JavaScript when you want to send more information than just a number. You can read more about this in the IO User Guide, starting from the Response Object section.