avatar_Everybody

Ajax проверка имени пользователя с использованием JQuery

Автор Everybody, 2008 Дек. 13, 17:23

« назад - далее »

0 Пользователи и 1 гость просматривают эту тему.

Ключевые слова [SEO] phpajaxjquery

Everybody

What happens?

The embedded javascript picks up the onblur event of the input field with id username.

It then sends a post request to check.php which checks the csv for the filename and returns the result.

The embedded javascript then updates the span element with id usernameResult.
The Code!

index.html - check source

jquery.js - a super javascript utility! check out jQuery

data.csv - CSV file that contains the user information
"username","first_name","last_name","password"
"john","John","Doe","123456"
"martin","Martin","Petrov","111111"

check.php

<?<br>$username = $_POST['username']; // get the username<br>$username = trim(htmlentities($username)); // strip some crap out of it<br>$file = '/home/js4hire/public_html/gafyd/data.csv'; // Here's the file. Notice the full path.<br><br>echo check_username($file,$username); // call the check_username function and echo the results.<br><br>function check_username($file_in,$username){<br>    $username=strtolower($username);<br>    $file = file($file_in);<br>    foreach ($file as $line_num => $line) {<br>  $line = explode(',',$line);<br>  $user = trim(str_replace('"','',$line[0]));<br>  if($username == strtolower($user)){<br>      return '<span style="color:#f00">Username Unavailable</span>';<br>  }<br>    }<br>    return '<span style="color:#0c0">Username Available</span>';<br>}<br>?>
Demo: _https://www.shawngo.com/gafyd/index.html

Похожие темы (5)