Hello!
Ajax calls under hulahop are not working any more!
They are working when called from user interaction (such as clicking
button), but not when called from timer or on application startup.
Last working pyjs version is 33b660a56040f07ea04f54de49706e2e00e57553.
I attached traceback, sample code and test server.
To try it, start the server: "python server.py" and then client:
"$HOME/pyjs/bin/pyjd index.py
Seva
--
Title: Ajax test
$HOME/pyjs/bin/pyjd index.py
INFO:pyjs.runners:conf:
[('runner', 'hulahop'),
('home', '/home/seva/.pyjd'),
('is_desktop', True),
('native_dnd', True),
('engine', 'hulahop')]
returning /home/seva/.pyjd/prefs.js for key NS_APP_PREFS_50_FILE
loaded
Traceback (most recent call last):
File "index.py", line 43, in <module>
main()
File "index.py", line 40, in main
test = Test()
File "index.py", line 17, in __init__
self.makeAjaxCall()
File "index.py", line 21, in makeAjaxCall
self.svc.echo(self, 'test arg')
File "/home/seva/byhr/env/pyjs/library/pyjamas/JSONService.py", line 259, in __call__
params, handler)
File "/home/seva/byhr/env/pyjs/library/pyjamas/JSONService.py", line 141, in sendRequest
self.headers):
File "/home/seva/byhr/env/pyjs/library/pyjamas/HTTPRequest.py", line 37, in asyncPost
returnxml, content_type, headers)
File "/home/seva/byhr/env/pyjs/library/pyjamas/HTTPRequest.py", line 182, in asyncImpl
res = xmlHttp.open(method, url)
File "<XPCOMObject method 'open'>", line 3, in open
xpcom.Exception: -1041039359 (NS_ERROR_NOT_INITIALIZED)
# -*- coding: utf-8 -*-
import pyjd # this is dummy in pyjs.
from pyjamas.ui.HTML import HTML
from pyjamas.ui.Button import Button
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.Timer import Timer
from pyjamas.JSONService import JSONProxy
class Test:
def __init__( self ):
self.svc = JSONProxy('svc', ['echo'])
RootPanel().add(Button('make ajax call', self.makeAjaxCall))
RootPanel().add(Button('make ajax call after 1s', self.scheduleCall))
self.makeAjaxCall()
self.scheduleCall()
def makeAjaxCall( self, *args, **kw ):
self.svc.echo(self, 'test arg')
def scheduleCall( self, *args ):
Timer(notify=self.makeAjaxCall, delayMillis=1000)
def onRemoteResponse( self, response, request_info ):
print 'server responded: %r' % response
def onRemoteError( self, code, errobj, request_info ):
message = errobj['message']
if code != 0:
print "HTTP error %d: %s" % (code, message)
else:
code = errobj['code']
"JSONRPC Error %s: %s" % (code, message)
def main():
pyjd.setup("http://localhost:8080/index.html")
test = Test()
pyjd.run()
main()
#!/usr/bin/env python
import json
import BaseHTTPServer
import SimpleHTTPServer
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_POST( self, *args, **kw ):
cl = int(self.headers['Content-Length'])
request = json.loads(self.rfile.read(cl))
id = request['id']
arg0 = request['params'][0]
self.log_message('post#%s: %r' % (id, arg0))
result = 'from server: %r' % arg0
resp = dict(result=result, error=None, id=id)
self.send_response(200)
self.end_headers()
self.wfile.write(json.dumps(resp))
self.wfile.flush()
http = BaseHTTPServer.HTTPServer(('', 8080), Handler)
http.serve_forever()