I am working on web development from the last few days. I am trying to send Form data to a Php page through Ajax, but the problem is that the Ajax code isn't working!

I've used the same code previously but it isn't working right now.

A bit of HTML,

<form id="Create" style="display: none;">
                <input type="text" name="Name" placeholder="Room name" required autofocus >  
                <select name="Category">
                    <option value="Technology">Technology</option>
                    <option value="Disscussion">Discussion</option>
                    <option value="Family">Family</option>
                    <option value="Others">Others</option>
                </select><br>
                <input type="radio" name="Type" value="Open">Open<br>
                <input type="radio" name="Type" value="Personal">Personal<br>
                <input type="submit" value="Confirm">
            </form>

A bit of JavaScript,

$('#Create').on('submit' , function (ev) {
    var form = document.getElementById("Create");
    var formdata = new FormData(form);

    ev.preventDefault();
    $.ajax({
    url : "./process_php/Chat1.php" ,
    data : $('#Create').serialize() ,
    cache : false,
    processData : false,
    type : "POST",
    //content-type = false ,
    success : function (response) {
        console.log(response);


    }

     });
    return false ;

});

And a bit of Php,

<?php

echo "hello" ;

?>

I am trying to send Form data to a Php page ( Actually I don't have anything in my Php file Except a single line which echoes out the word "hello" ) and log the response back in my console, I don't know why My code doesn't even send it. I've verified this by checking the network tab in developer options in my browser.

I've spent a few hours online searching for my answer but couldn't find it.

1 Answers

0
K. P. On

Instead of

data : $('#Create').serialize(),

You should write

data : { $('#Create').serialize() },

You are missing the curly braces

Not sure if it solves your problem, but this is definitely a mistake.