Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling a back end URL using javascript channel API
    text
    copied!<p>Handler Implementation</p> <pre><code>class TestHandler(RequestHandler, Jinja2Mixin): def get(self): channel_id = str(random.randint(1, 10000)) + str(datetime.now()) chat_token = channel.create_channel(channel_id) context = {'channel_id': channel_id, 'chat_token': chat_token} return self.render_response('test.html', **context) def post(self): channel_id = str(random.randint(1, 10000)) + str(datetime.now()) chat_token = channel.create_channel(channel_id) context = {'channel_id': channel_id, 'chat_token': chat_token} return self.render_response('test.html', **context) </code></pre> <p>HTML Implementation</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" language="javascript" src="/static/js/jquery-1.6.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" language="javascript" src="/static/js/backend.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="post" id="testform" name="testform"&gt; &lt;br&gt;&lt;label name="channel_id" id="channel_id"&gt;{{channel_id}}&lt;/label&gt; &lt;br&gt;&lt;label name="chat_token" id="channel_id"&gt;{{chat_token}}&lt;/label&gt; &lt;input type="submit" id="btnsubmit" class="btnsubmit" name="btnsubmit" value="submit" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>jQuery implementation</p> <pre><code> $(document).ready(function () { var token =$('#channel_id').val() alert(token) var channel = new goog.appengine.Channel(token); var socket = channel.open(); socket.onopen = onOpened; onOpened = function() { connected = true; var xhr = new XMLHttpRequest(); xhr.open('POST','/dashboard/', true); xhr.send(); }; socket.onmessage = onMessage; socket.onerror = onError; socket.onclose = onClose; }); </code></pre> <p>I want to call a Back end handler. I do not know how to do it. This is what i have done . Can anyone give a help ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload