Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

javascript - 在AJAX中执行POST查询时,在控制台中收到“未定义数据”错误(Receiving 'data is not defined' error in console when doing a POST query in AJAX)

I'm working on a form that writes to a SharePoint list when submitting as a new entry in the list.(我正在处理一个表单,该表单在列表中作为新条目提交时会写入SharePoint列表。)

I've got the AJAX code in place and it seems to connect out to the list okay, however I'm receiving the following error when attempting to create the entry:(我已经准备好了AJAX代码,似乎可以连接到列表了,但是尝试创建该条目时收到以下错误:)
SCRIPT5009: 'data' is not defined

Here's my code, the data is pulled from the text boxes in the form, I'm just not certain whether they've been added to the JSON array properly.(这是我的代码,数据是从表单中的文本框中提取的,我不确定它们是否已正确添加到JSON数组中。)

function AddListItem() {  
    var ref = $("#ref").val();  
    var userID = $("#userID").val();  
    var impact = $("#impact").val();

    $.ajax  
        ({  
        url: "https://office4.bt.com/sites/ccim/Portal/_api/web/lists/GetByTitle('ImpactFeedback')/items",  
        type: "POST",  
        data: JSON.stringify  
        ({  
            __metadata:  
            {  
                type: "SP.Data.TestListItem"  
            },  
            Title: ref,  
            UIN: userID,
            Issue: impact,
            Email: email,  
        }),  
        headers:  
        {  
            "Accept": "application/json;odata=verbose",  
            "Content-Type": "application/json;odata=verbose",  
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
            "X-HTTP-Method": "POST"  
        },  
        success: function(data, status, xhr)  
        {  
            retriveListItem();  
        },  
        error: function(xhr, status, error)  
        {  
            $("#ResultDiv").empty().text(data.responseJSON.error);  
        }  
    });  
}  
  ask by GetWhimsical translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In your error callback, change:(在错误回调中,更改:)

$("#ResultDiv").empty().text(data.responseJSON.error);  

to(至)

$("#ResultDiv").empty().text(xhr.responseJSON.error);  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...