В моем js-файле я отправляю массив данных в свой php-файл, и я хочу напечатать имя в #NAME и пароле в #PASSWORD, но я получаю оба значения имени и пароля в #NAME и #PASSWORD, что-то вроде этого :Как вернуть определенные данные из php в jquery ajax?
, как я хочу его напечатать:
$("#name").keyup(function() {
var form = $("#form").serialize();
$.ajax({
type: "POST",
url: "index.php",
data: form,
success: function(data) {
$("#NAME").html(data);
}
});
});
$("#password").keyup(function() {
var form = $("#form").serialize();
$.ajax({
type: "POST",
url: "index.php",
data: form,
success: function(data) {
$("#PASSWORD").html(data);
}
});
});
<html>
<body>
<form id="form" action="index.php" method="post">
Name :
<input type="text" name="name" id="name" /><span id="NAME">I want name here from index.php, but it returns both name and password</span>
<br/>
<br/>Password :
<input type="password" name="password" id="password" /><span id="PASSWORD">I want password here from index.php, but it returns both</span>
<br/>
<br/>
is there any other way of doing it in the same index.php file?
</form>
<script src="jquery.js"></script>
<script src="js.js"></script>
</body>
</html>