gpt4 book ai didi

javascript - Uncaught ReferenceError : error is not defined in Ajax Callback

转载 作者:行者123 更新时间:2023-12-03 11:33:34 28 4
gpt4 key购买 nike

在我的应用程序中,我从 Sharepoint 日历列表中获取事件列表。那部分工作完美。但是,在获得结果集合后,对于每个项目,我需要获取显示表单 Url,这是另一个带有 ListItem ID 的 REST 调用。

但是我收到以下错误,但我仍然不知道问题可能是什么

Uncaught ReferenceError: error is not defined App.js:87(anonymous function) App.js:87$.ajax.error App.js:40c jquery-1.9.1.min.js:22p.fireWith jquery-1.9.1.min.js:22k jquery-1.9.1.min.js:24send.r

我的代码基于这个答案: https://sharepoint.stackexchange.com/questions/119236/how-to-get-the-display-form-url-using-rest

我改编的代码是这样的:

   var SPHostUrl;
var SPAppWebUrl;
var ready = false;

// this function is executed when the page has finished loading. It performs two tasks:
// 1. It extracts the parameters from the url
// 2. It loads the request executor script from the host web
$(document).ready(function () {
var params = document.URL.split("?")[1].split("&");
for (var i = 0; i < params.length; i = i + 1) {
var param = params[i].split("=");
switch (param[0]) {
case "SPAppWebUrl":
SPAppWebUrl = decodeURIComponent(param[1]);
break;
case "SPHostUrl":
SPHostUrl = decodeURIComponent(param[1]);
break;
}
}

// load the executor script, once completed set the ready variable to true so that
// we can easily identify if the script has been loaded
$.getScript(SPHostUrl + "/_Layouts/15/SP.RequestExecutor.js", function (data) {
ready = true;
getItems();
});
});

function getListItemFormUrl(webUrl, listName, listItemId, formTypeId, complete, failure) {
$.ajax({
url: webUrl + "/_api/web/lists/GetByTitle('" + listName + "')/Forms?$select=ServerRelativeUrl&$filter=FormType eq " + formTypeId,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var url = data.d.results[0].ServerRelativeUrl + '?ID=' + listItemId
complete(url);
},
error: function (data) {
failure(data);
}
});
}



// this function retrieves the items within a list which is contained within the parent web
function getItems() {

// only execute this function if the script has been loaded
if (ready) {

// the name of the list to interact with
var listName = "Events";

// the url to use for the REST call.
var url = SPAppWebUrl + "/_api/SP.AppContextSite(@target)" +

// this is the location of the item in the parent web. This is the line
// you would need to change to add filters, query the site etc
// "/web/lists/getbytitle('" + listName + "')/items?" +
"/web/lists/getbytitle('" + listName + "')/items?$select=Title,Category,EventDate,Description,EncodedAbsUrl,ID" +
"&@target='" + SPHostUrl + "'";

// create new executor passing it the url created previously
var executor = new SP.RequestExecutor(SPAppWebUrl);

// execute the request, this is similar although not the same as a standard AJAX request
executor.executeAsync(
{
url: url,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {

// parse the results into an object that you can use within javascript
var results = JSON.parse(data.body);
var events = [];
$.each(results.d.results, function (i, obj) {

//Usage
getListItemFormUrl(SPAppWebUrl, 'Calendar', obj.ID, 4,
function (url) {
console.log('Display from url for list item: ' + url);
},
function (sender, args) {
console.log(JSON.stringify(error));
})

//use obj.id and obj.name here, for example:
var event = {
date: Date.parse(obj.EventDate).toString(),
type: obj.Category,
title: obj.Title,
description: obj.Description,
url: obj.EncodedAbsUrl + 'DispForm.aspx?ID=' + obj.ID
}
events.push(event);
});
var myJsonString = JSON.stringify(events);

$("#eventCalendarInline").eventCalendar({
jsonData: events,
openEventInNewWindow: true,
showDescription: true,
txt_GoToEventUrl: "Go to event"
});

Communica.Part.init();

},
error: function (data) {

// an error occured, the details can be found in the data object.
alert("Ooops an error occured");
}
});
}
}

最佳答案

//用法下:

function (sender, args) {
console.log(JSON.stringify(error));
})

错误似乎未定义

关于javascript - Uncaught ReferenceError : error is not defined in Ajax Callback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26632130/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com