Hi, I am trying to incorporate some AJAX into a project I'm working on and I'm having some problems getting it to function as I would like. I have some JavaScript functions which will check for empty fields, wrong data type etc and they will display a message in a special field for error reporting.
The AJAX part of the validation will take the user input and check if it matches an entry in the database.If an input is valid, it displays a message saying 'valid'. If not, it displays 'This username has already been taken'. I just cannot work out how to link the PHP part of the functionality with JavaScript i.e. if all my data type checks are passed, how can I distinguish between a valid and invalid server response?
Here is some code:
This shows the response handler for the AJAX functionality so every time the server sends back a response, the checkID function is called.
Withing checkID all the input types etc are checked but it the PHP code that checks for existing entries in the database.
edit:code removed
PHP code:
edit:code removed - problem solved
Would appreciate some help on this. Im newish to both PHP and JavaScript so im not sure about sharing variables between both the server side and client side.
Cheers
The AJAX part of the validation will take the user input and check if it matches an entry in the database.If an input is valid, it displays a message saying 'valid'. If not, it displays 'This username has already been taken'. I just cannot work out how to link the PHP part of the functionality with JavaScript i.e. if all my data type checks are passed, how can I distinguish between a valid and invalid server response?
Here is some code:
This shows the response handler for the AJAX functionality so every time the server sends back a response, the checkID function is called.
Withing checkID all the input types etc are checked but it the PHP code that checks for existing entries in the database.
edit:code removed
PHP code:
edit:code removed - problem solved
Would appreciate some help on this. Im newish to both PHP and JavaScript so im not sure about sharing variables between both the server side and client side.
Cheers
Last edited: