jQuery AJAX请求不是一个函数

时间:2012-01-26 17:27:50

标签: jquery ajax

我需要第二双眼睛,因为看不出它为什么会回来:

$("#message").removeClass().addClass(data.error === true ? "error" : "success").html(data.msg).show is not a function

我的代码如下:

$.ajax({
        type : 'POST',
        url : 'postcode-lookup.php',
        dataType : 'json',
        data: {
            postcode : $('#postcode').val()
        },
        success : function(data){
            $('#waiting').hide(500);
            $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success').text(data.msg).show(500);
            if (data.error === true)
                $('#restricted_locator').show(500);
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            $('#waiting').hide(500);
            $('#message').removeClass().addClass('error').text('There was an error.').show(500);
            $('#restricted_locator').show(500);
        }
    });

1 个答案:

答案 0 :(得分:0)

如果data.msgundefined,则$("#message")....html(data.msg)将返回一个字符串,并在字符串上调用show方法将为您提供该错误。

<强> Demo