View Single Post
  #1  
Old 02-03-2014, 11:33 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,570
IntoRain is on a distinguished road
Default jQuery and Mysidia: A struggle

I know well that mysidia is anti-javascript currently, specially ajax, due to the way the pages are rendered. However, I started this and I really want to find a way.

So in my little test site for 1.3.4, I've been trying to use ajax to check if the username and e-mail already exists and tell the user real-time. I've accomplished this somewhat, but I came across two problems:

1) The function I'm using to verify the variables sent by the ajax request (for example, username and email) became a page itself (since most .php files and their respective functions are converted to html), like so http://website.com/register/checkusernamefunction. lol
To avoid this (access from users to pages that shouldn't be pages), I throw an error if the variable through post is empty (if username has no value). Which is kind of not a good way to do it... Is there a way to correct this? Maybe stop the page from rendering automatically?

2) I'm doing the verification of the word I write in the input field for each key press

PHP Code:
$('input#username').keyup(function(){}) 
but sometimes it seems it won't keep up. I made it display the .val() of the field and my results were: Like it will keep changing between the full word I wrote and part of the word or just display half the word. I think it's because of the delay of having to query the database for each key press or something that causes it to spazz. I'm honestly thinking of creating a buffer for this, lol
I tried using keydown and it stays behind one character for some reason (if I write "SampleAccount2" it will assume I wrote "SampleAccount", which is not as random as keypress or keyup).
Instead of each key press, I thought to use it with each click on the field, but it's kinda impractical for the users, since they have to click to write the username and then click outside the input field and then click the input again to check if it's being used.
I'm quite a newbie at this jquery thing, so I'm asking if these are the best ways to do it or if there are alternatives.

Also another thing. My question is: is it bad practice to have the script functions displayed on the page directly instead of having them all in a single file .js? I'm echoing the javascript I need in each page since including the file didn't seem to work
__________________


asp.net stole my soul.
Reply With Quote