I am making a webpage using CherryPy for the server side, HTML, CSS and jQuery on the client side. I also use the mySQL database.
I have a working form for users to register on the site - create a username and password. I am using jQuery to send an AJAX POST request to CherryPy, which queries the database to find out if this username exists. If the username exists, notify the user if it is not, add it to the database and receive a warning.
$.post('submit', postdata, function(data) { alert(data); });
Successful jQuery POST.
I want to change the form so that instead of verifying that the username exists when sending, the GET request is executed in the same way as with the blur event from entering the username. The function is called and it goes to CherryPy, but then I get the error message: HTTPError: (404, 'Missing parameters: username') .
$.get('checkUsername', getdata, function(data) { alert(data); });
Bad jQuery GET.
The CherryPy:
@cherrypy.expose def submit(self, **params): cherrypy.response.headers['Content-Type'] = 'application/json' e = sqlalchemy.create_engine('mysql://mysql: pw@localhost /6470') c = e.connect() com1 = "SELECT * FROM `users` WHERE `username` = '" + params["username"] + "'" b = c.execute(com1).fetchall() if not len(b) > 0: com2 = "INSERT INTO `6470`.`users` (`username` ,`password` ,`website` ,`key`) VALUES ('" com2 += params["username"] + "', MD5( '" + params["password"] + "'), '', NULL);" a = c.execute(com2) c.close() return simplejson.dumps("Success!") c.close() return simplejson.dumps("This username is not available.") @cherrypy.expose def checkUsername(self, username): cherrypy.response.headers['Content-Type'] = 'application/json' e = sqlalchemy.create_engine('mysql://mysql: pw@localhost /6470') c = e.connect() command = "SELECT * FROM `users` WHERE `username` = '" + username + "'" a = c.execute(command).fetchall(); c.close() sys.stdout.write(str(a)) return simplejson.dumps("")
I don't see the differences between the two, so I donβt know why the GET request gives me a problem. Any understanding of what I might be doing wrong would be helpful.
If you have any ideas about jQuery, CherryPy, configuration files, whatever, I would really appreciate it.
* * EDIT ****
At the request of some friends, here is more information.
How can I calculate getdata:
var getdata = $("#username").val();
URL requested by the server: (Well, this is what PuTTy says, going from server to server, I donβt know the server side stupidities)
GET /checkUsername?noram HTTP/1.1