Вы можете рассмотреть AJAX вызов с jQuery .
Вот пример кода:
$.ajax
({
type: "POST",
//the url where you want to sent the userName and password to
url: "http://your-url.com/secure/authenticate.php",
dataType: 'json',
async: false,
//json object to sent to the authentication url
data: '{"userName": "' + userName + '", "password" : "' + password + '"}',
success: function (){
//do any process for successful authentication here
}
});
Конечно, сначала вам нужно будет ввести введенное пользователем значение из полей userName и password .
На стороне сервера вы можете выполнить всю проверку и отправить простое сообщение, такое как authenticated или failed . success часть вызова ajax предназначена для выполнения любого процесса после аутентификации пользователя.
Подробнее о jQuery AJAX http://api.jquery.com/jQuery.ajax/
** ОБНОВЛЕНИЕ **
Скажем, у вас есть этот HTML-код:
<input type="text" name="username" id="username" class="text" maxlength="30" />
<br />
<input type="password" name="password" id="password" class="text" maxlength="30" />
<br />
<input type="submit" name="btnSubmit" id="btnSubmit" />
Вы можете использовать этот скрипт jQuery для сбора ввода пользователя и выполнения вызова ajax:
$(document).ready(function () {
//event handler for submit button
$("#btnSubmit").click(function () {
//collect userName and password entered by users
var userName = $("#username").val();
var password = $("#password").val();
//call the authenticate function
authenticate(userName, password);
});
});
//authenticate function to make ajax call
function authenticate(userName, password) {
$.ajax
({
type: "POST",
//the url where you want to sent the userName and password to
url: "http://your-url.com/secure/authenticate.php",
dataType: 'json',
async: false,
//json object to sent to the authentication url
data: '{"userName": "' + userName + '", "password" : "' + password + '"}',
success: function () {
//do any process for successful authentication here
}
})
}