나는 학습 목적으로 만 PHP 스크립트를 가지고 있습니다. 내 웹 응용 프로그램 아약스 양식에 사용하고 싶습니다. 절대로 PHP 스크립트를 테스트하는 것이 아닙니다. 그래서 아약스 양식 이름과 암호를 통해 보내고 싶습니다, PHP 스크립트에서 올바른지 확인하고 성공할 때 (로그인 및 암호가 올바른 경우) 또는 오류 (일치하지 않을 때)를 반환합니다. 내 문제는 js 또는 jQuery에서 올바르게 보내고받는 방법입니다. 누가 더 나은 아이디어를 가지고 나를 도울 수 있고/또는 이것을하는 기능을 더 안전하게 할 수 있습니까?ajax 양식 제출 및 수신
는 I에 유래에 발견하고이 스크립트 tryed :
//bind an event handler to the submit event for your login form
$('#login_form').live('submit', function (e) {
//cache the form element for use in this function
var $this = $(this);
//prevent the default submission of the form
e.preventDefault();
//run an AJAX post request to your server-side script, $this.serialize() is the data from your form being added to the request
$.post($this.attr('action'), $this.serialize(), function (responseData) {
//in here you can analyze the output from your server-side script (responseData) and validate the user's login without leaving the page
});
});
을 그리고이
<?php
$username = $_GET["name"];
$password = $_GET["password"];
if($username="*****" && $password==********)
{
header('Location:http://*****************/jaz/imes/index.html?login="success"');
}else{
header('Location:http://*****************/jaz/imes/index.html?login="error"');
}
?>
을? : 같은 PHP 스크립트에서 작동 할 수 있는지 궁금 해서요 그리고 말했듯이 단지입니다 그것에 대해 더 많은 것을 배우기위한 테스트 스크립트.
.live()'은 더 이상 사용되지 않습니다. 대신'.on()'을 사용하십시오. – Brad