如何通过javascript将输入字段的值发送到php文件并获取返回的值[重复]

This question already has an answer here:

I have this html code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
     <form action="test.php" method="get">
        <input type="text" placeholder="City" id="city" />
        <br />
        <input type="text" placeholder="Region" id="region" />
     </form>
     <div id="result"></div>
</body>
</html>

And this is my php code:

<?php
     $city = $_GET['city'];
     $region = $_GET['region'];
     $result = "You entered " . $city . " and " . $region;
?>

And I want to get the $result from the php file immediately and show it in the div with id result.

</div>

As it turns out from your comments, you need to know how to do AJAX. Use jQuery and some hints on the jS part :

$('#region').mouseout(function() {
    $('#result').fadeOut();
    $.ajax({
        url: window.location.href+"api/user/"+$(this).val(),
        dataType: "html"
    }).done(function(data) {
        $('#result').fadeIn();
        $('#result').text(data);
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

</div>