[英]Uncaught TypeError: Cannot read property 'ajax' of undefined When I'm trying to send data to url
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: 我创建了一个表单来获取用户的反馈,我只是想将表单数据发送到url,但是我收到了这个错误:
Uncaught TypeError: Cannot read property 'ajax' of undefined
未捕获的TypeError:无法读取未定义的属性'ajax'
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. 错误消息表明jQuery未定义。 You must include jQuery before doing anything with $.ajax
在使用$ .ajax做任何事情之前,你必须包含jQuery
Put this line in the html page before your script : <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
将此行放在脚本之前的html页面中:
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
That means that jquery has not been loaded. 这意味着尚未加载jquery。
Make sure that you have the script in your html, and also wrap the call to this function sendData
inside a 确保你的html中有脚本,并且还包含对a函数
sendData
的调用
$(document).ready(function(){
//do stuff
})
I had the same problem and I solved it, by changing the dollar symbol $ with jQuery . 我有同样的问题,我解决了它,通过使用jQuery更改美元符号$。
jQuery.ajax({ type: "POST", url: "...", data: jQuery('myForm').serialize(), success: function(msg) { console.log('success!'); }, });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.