【问题标题】:Uncaught TypeError: Cannot call method 'ajax' of undefined [closed]未捕获的类型错误:无法调用未定义的方法“ajax”[关闭]
【发布时间】:2013-01-18 16:52:18
【问题描述】:

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

未捕获的类型错误:无法调用未定义的方法 'ajax'

为什么会出现这个错误?

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;
}

【问题讨论】:

    标签: javascript jquery ajax wordpress wordpress-theming


    【解决方案1】:

    您需要在页面中包含jquery.js,方法是将此行放在<head></head> 部分中:

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

    您收到错误是因为 jQuery 使用的 $ 变量尚未启动,因此 $.ajax() 函数不存在。

    【讨论】:

    • 还是报错,客户说是wordpress更新到3.5后出现这个错误,有什么解决办法吗?
    猜你喜欢
    • 2012-10-16
    • 2013-08-31
    • 2011-11-12
    • 2013-09-14
    • 2013-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多