Log in page using cherrypy and Javascript

postkid

New Member
I am trying to create Log in page using python Cherrypy and JavaScript...I cant link the two.Expected output = if username=='Bob' ans Password=='123' then display 'Welcome BOB'else then display 'invalid user' in the HTML pageI am attaching the HTML file as well as the python file. index.html\[code\]<html><head><title>Welcome to AJAX Page</title></head><body bgcolor=E6F0FF><script type="text/javascript">function xml_http_post(url, data,callback) { var req = false; try { // Firefox, Opera 8.0+, Safari req = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } req.open("POST", url, true); req.onreadystatechange = function() { if (req.readyState == 4) { callback(req); } } req.send(data);}function test_button() { var data1 = document.test_form.user.value; var data2 = document.test_form.passw.value; if(data1=="" || data2=="") { alert("Username or Password cannot be blank") } var data= http://stackoverflow.com/questions/14597686/data1 + data2; xml_http_post("index.html", data, test_handle)}function test_handle(req) { var elem = document.getElementById('test_result') elem.innerHTML = req.responseText}</script><center><br><br><br><br><br><br><img src="http://stackoverflow.com/questions/14597686/rebaca.jpg" border="1"><br><br><form name=test_form><font face= "Calibri">Username : <input type="text" name="user" value="" size="25"><br><br>Password : <input type="password" name="passw" value="" size="25"><br><br><b><span id="test_result">Hello User! </span></b><br><br><input type=button onClick="test_button();" value="http://stackoverflow.com/questions/14597686/Login" title="start"><input type=reset></font></form></center></body></html>\[/code\]ajax_app.py\[code\]"""ajax_app.pyDemo of AJAX using: - cherrypy - simplejson"""import cherrypyimport webbrowserimport osimport simplejsonimport sysMEDIA_DIR = os.path.join(os.path.abspath("."), "media")class AjaxApp(object): @cherrypy.expose def index(self): return open(os.path.join(MEDIA_DIR, 'index.html')) @cherrypy.expose def submit(self, name): print name cherrypy.response.headers['Content-Type'] = 'application/json' return simplejson.dumps(dict(title="Hello, %s" % name))config = {'/media': {'tools.staticdir.on': True, 'tools.staticdir.dir': MEDIA_DIR, } }def open_page():webbrowser.open("localhost:8080/")cherrypy.engine.subscribe('start', open_page)herrypy.tree.mount(AjaxApp(), '/', config=config)cherrypy.engine.start()\[/code\]
 
Back
Top