javascript - Jquery post response not available -
i'm new javascript, , problem may trivial need help. goal send post python server based on tornado.
in following function :
var machin = $.post( '/room/testroom', function( data ) { truc = data; return truc;
i never content of truc
. variable has url inside used create new websocket connection.
when console.dir(machin);
see wanted responsetext
wanted url in console, i'm not able outside of console.
the variable data inside function has wanted data, if : alert(data)
see alert box wanted url.
feel free ask me details may not entirely clear.
server side, python code one:
def post(self, roomname): print 'je poste' db = connect(host=config.sqlserver, user=config.sqluser, passwd=config.sqlpass, db=config.sqldb) cursor = db.cursor() uri = self.request.uri url = uri.split('/') roomname = url[2] sql = 'select roomid abcd_un roomname = %s', [roomname] cursor.execute(*sql) roomid = cursor.fetchone() print 'roomid', type(roomid) roomid = str(roomid[0]) roomid = roomid.decode() fullurl = 'ws://' + self.request.host + '/socket/' + roomid #print uri db.close() wsurl = { 'url': fullurl, } wsurl_encoded = tornado.escape.json_encode(wsurl) self.write(wsurl_encoded)
try:
var machin = function (){ $.post( '/room/testroom', function( data ) { truc = json.parse(data); return truc; }
now call function:
var response = machin();
Comments
Post a Comment