Web开发。 阿贾克斯

Can someone please guide me through where am I going wrong in this piece of code below

index.php :-

<script type="text/javascript">
function fun(){
    alert("H");
    $.ajax({
    type: "POST",
    url: 'test.php',
    data: {name: 'Wayne', age: 27},
    success: function(data){
        alert(data);
    },
    error: function(error){
        alert(error);
    }
});
    alert("HE");
    }
    </script>
    <input type="button" value="submit" onclick="fun()" /> 

test.php :-

<?php
    $name = $_POST['name'];
    $age = $_POST['age'];
    echo $name.$age;
?>

I'm not getting any output nor any error.

The problem is in the javascript code, specifically in how you're calling the function. Try this instead:

// javascript
document.getElementById('do-fun').addEventListener('click',function(){
    fun();
});

// html
<input type="button" value="submit" id="do-fun" />