javascript - 未捕获的类型错误 : Cannot call method 'ajax' of undefined

标签 javascript jquery ajax wordpress wordpress-theming

<分区>

我已将 wordpress 更新到 3.5 并收到此错误,j.s 无法正常工作。

Uncaught TypeError: Cannot call method 'ajax' of undefined

为什么会出现此错误?

function goToIndexforsave() {
    document.getElementById('sorted_successmsg_div').innerHTML = 'processing ...';
    var img_save_url = 'http://www.holidayvillas4hire.com/index.php?page=sort_image&pid='+document.getElementById('image_sort').value;

    $.ajax({
        url: img_save_url ,
        type: 'GET',
        dataType: 'html',
        timeout: 20000,
        error: function() {
            alert('Error loading agent favorite property.');
        },
        success: function(html) {
            document.getElementById('sorted_successmsg_div').innerHTML = html;
        }
    });
    return false;
}

最佳答案

您需要包括 jquery.js在您的页面中,将此行放在 <head></head> 中部分:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

您收到错误是因为 $ jQuery 使用的变量还没有被初始化,因此 $.ajax()函数不存在。

关于javascript - 未捕获的类型错误 : Cannot call method 'ajax' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14403681/

相关文章:

javascript - 动态评论功能代码

javascript - 如何从所有功能中返回单个字段?

javascript - 为什么在添加动画 css 类时不起作用

javascript - 从两个输入文本字段中,当我在其中一个输入数据时,如果在下一个输入了某些内容,它必须消失。

javascript - XMLHttpRequest.open() 方法中的错误函数不正确

javascript - Ajax 表单提交设置 enctype

javascript - 自定义 jQuery 函数随机未定义

javascript - Jquery Datatables 选择除第一页以外的其他页面上的行

JQuery如何选择父级而不是子级

ajax - POST 无法连接到 Web 服务