学習目的のみのphpスクリプトがあります。Web アプリの ajax フォームで使用したいと思います。これはphpスクリプトのテストです。したがって、ajax フォーム名とパスワードを介して送信したいと思います。php スクリプトでは、正しいかどうかがチェックされ、成功 (ログインとパスワードが正しい場合) またはエラー (一致しない場合) が返されます。私の問題は、jsまたはjQueryで正しく送受信する方法です。これを行うためのより良いアイデアやより安全な機能で私を助けることができる人はいますか?
私はstackoverflowで見つけて、このスクリプトを試しました:
//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スクリプトで次のように機能するかどうか疑問に思っていましたか?:
<?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"');
}
?>
前述したように、これは単なるテスト スクリプトであり、詳細を学習するためのものです。