Skip to content

Instantly share code, notes, and snippets.

@pineoc
Created December 14, 2017 17:15
Show Gist options
  • Save pineoc/83a81aaca0583053994afd7a54e47144 to your computer and use it in GitHub Desktop.
Save pineoc/83a81aaca0583053994afd7a54e47144 to your computer and use it in GitHub Desktop.
ajax + php login sample
<?php
// 이 코드는 받은 키 값을 출력해줍니다.
foreach ($_POST as $key => $value)
echo $key.": ".$value;
$member = $_POST;
foreach ($member as $value) {
echo " ".$value;
}
?>
<!--이 코드는 모바일에 들어갈 코드입니다.-->
<html>
<head>
<title>login!</title>
</head>
<body>
<div>
<input id="inputId" type="text" name="userId"/>
<input id="inputPwd" type="password" name="userPwd" />
<button id="submit">submit</button>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
let btn = document.querySelector('#submit');
btn.addEventListener('click', submitFunction);
function submitFunction() {
const data = {
userId: document.querySelector('#inputId').value,
userPwd: document.querySelector('#inputPwd').value
};
$.ajax({
// 여기에 있는 주소는 서버 주소로 수정해줘야합니다.
// 대략 이런식으로 개발하면 될 듯 하네요.
url: "http://localhost/login-post.php",
type: "post",
data: data,
success: function(data) {
console.log('success, ' + data);
}
});
}
</script>
<!--여기에 코르도바 스크립트가 들어가겠지요.-->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment