javascript 类型错误:a 为空

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7699306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 00:59:51  来源:igfitidea点击:

TypeError: a is null

javascriptajaxjquery

提问by Amin

I'm using the following jQuery Ajax call... anyhow it's not working.

我正在使用以下 jQuery Ajax 调用...无论如何它不起作用。

Error:TypeError: a is null

错误:TypeError: a is null

Here is my Code:

这是我的代码:

var prefixUrl = "autocomplete?action=complete&id=";
$('#complete-field').bind('keyup', function(){
var url =  prefixUrl + escape($('#complete-field').val());
$.ajax({
    type: "GET",
    getUrl:url,
    dataType: "xml",
    success: function(responseXML) {
        var composers = responseXML.getElementsByTagName("composers")[0];
        if (composers.childNodes.length > 0) {

            $('#complete-table').css("border", "1px solid green");
            $('#complete-table').css("margin", "128px 0 0 -82px");

            for (var loop = 0; loop < composers.childNodes.length; loop++) {
                var composer = composers.childNodes[loop];
                var firstName = composer.getElementsByTagName("firstName")[0];
                var lastName = composer.getElementsByTagName("lastName")[0];
                var composerId = composer.getElementsByTagName("id")[0];

                appendComposer(firstName.childNodes[0].nodeValue, lastName.childNodes[0].nodeValue, composerId.childNodes[0].nodeValue);
            }
        }
    },
    error:function (xhr, ajaxOptions, thrownError) {
        alert('xhr.status: ' + xhr.status);
        alert(thrownError);
    }
  });
});

Any Idea please?

请问有什么想法吗?

Many Thanks

非常感谢

回答by Andbdrew

$.ajax({
    type: "GET",
    getUrl:url,
    ...

should be

应该

$.ajax({
    type: "GET",
    url: url,
    ...

See the docs at http://api.jquery.com/jQuery.ajax/

请参阅http://api.jquery.com/jQuery.ajax/ 上的文档