6

I have created a form to get feedback from user, I’m simply trying to send form data to url, but I’m getting this error:

Uncaught TypeError: Cannot read property 'ajax' of undefined

function sendData(){
    $.ajax({
        url: "www.yashkjhsah.php",
        type: "POST",
        async: true,
        data: $(".contacts_form").serialize(),
        dataType: "html",
        success: function(data) 
        {
            alert(data);
            if(data!="Error in Insert Query!")
            {
                alert("Thank you for Enquiry we will send answer in your Mail.");
            }
            else
            {
                alert("Error while saving the data");
            }
        }
    });
}
dakab
  • 5,379
  • 9
  • 43
  • 67

3 Answers3

4

The error message says that jQuery is not define. You must include jQuery before doing anything with $.ajax

Put this line in the html page before your script : <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

TGrif
  • 5,725
  • 9
  • 31
  • 52
4

I had the same problem and I solved it, by changing the dollar symbol $ with jQuery.

 jQuery.ajax({
                type: "POST",
                url: "...",
                data: jQuery('myForm').serialize(),
                success: function(msg) {
                    console.log('success!');
                },
            });
gassio
  • 185
  • 2
  • 13
0

That means that jquery has not been loaded.

Make sure that you have the script in your html, and also wrap the call to this function sendData inside a

$(document).ready(function(){
//do stuff
})
Manjar
  • 3,159
  • 32
  • 44