PHP not returning Ajax Call Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of PHP not returning Ajax Call without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m trying to send over the data from my textarea using an ajax call to my PHP file, but we aren’t getting any response back from the PHP file.

<textarea id="area" cols="70" rows="30"></textarea>
<button id="submit">Submit</button>

<script>
$('#submit').click(function (e) {
    e.preventDefault();

    var info = $('#area').val();
    $.ajax({
        type: "POST",
        url: 'pages/assignments/response.php',
        data: {area: info}
    });
});
</script>
<?php
    if (!empty($_POST['area'])) {
        $success = json_encode('succes');
        return $succes;
    };
?>

— # Answer # —

I thought I had already tried an echo in this piece of code, but I think I just missed the output on the webpage and thought it wasn’t working.

<?php
    if (!empty($_POST['area'])) {
        echo "success";
    };
?>

Answer

Thanks Mickael for the answer!

I completely forgot to add an echo to my code.

<?php
    if (!empty($_POST['area'])) {
        $succes = json_encode('succes');
        echo $succes();
    };
?>
We are here to answer your question about PHP not returning Ajax Call - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji