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");
}
}
});
}
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>
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
})
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!'); }, });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.