简体   繁体   English

未捕获的TypeError:无法读取未定义的属性'ajax'当我尝试将数据发送到url时

[英]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.

相关问题 未捕获的类型错误:尝试显示数据时无法读取未定义的属性“0” - Uncaught TypeError: Cannot read property '0' of undefined when trying to display data 我在 axios 补丁 api 中收到“Uncaught (in promise) TypeError: Cannot read property 'data' of undefined”错误 - I'm getting “Uncaught (in promise) TypeError: Cannot read property 'data' of undefined” error in axios patch api 捕获TypeError:尝试将数据绑定到Kendo Grid时无法读取未定义(匿名函数)的属性&#39;uid&#39; - Getting Uncaught TypeError: Cannot read property 'uid' of undefined(anonymous function) when trying to bind data to Kendo Grid 未捕获的类型错误:当图中没有数据时,无法读取未定义的属性“标签” - Uncaught TypeError: Cannot read property 'label' of undefined when No Data In Graphs 我收到一个未捕获的类型错误:无法读取 null 的属性“ID”。 仅在尝试访问对象的最后两项时 - I'm getting an Uncaught TypeError: Cannot read property 'ID' of null. Only when trying to access the last two items of an Object “未捕获的TypeError:在尝试从对象获取属性时无法读取未定义的属性&#39;x&#39; - “Uncaught TypeError: Cannot read property 'x' of undefined” when trying to get a property from an object select2 ajax:未捕获的TypeError:无法读取未定义的属性“上下文” - select2 ajax : Uncaught TypeError: Cannot read property 'context' of undefined 未捕获的类型错误:无法使用 Laravel 和 AJAX 读取未定义的属性“” - Uncaught TypeError: Cannot read property '' of undefined using Laravel and AJAX 未捕获的TypeError:在Ajax调用后无法读取未定义的属性&#39;appendChild&#39; - Uncaught TypeError: Cannot read property 'appendChild' of undefined after Ajax call 未捕获的类型错误:无法读取 AJAX object 上未定义的属性“映射” - Uncaught TypeError: Cannot read property 'map' of undefined on AJAX object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM