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