0

Successfully adding items to a list but success handler not firing. Anybody know why?

function addListItem() {

    var guidance1 = $("#guidance1").val();
    var guidance2 = $("#guidance2").val();
    var guidance3 = $("#guidance3").val();
    var guidance4 = $("#guidance4").val();
    var guidance5 = $("#guidance5").val();

var siteUrl = _spPageContextInfo.webAbsoluteUrl;
var fullUrl = siteUrl + "/_api/web/lists/GetByTitle('Travel Request')/items";

$.ajax({
    url: fullUrl,
    type: "POST",
    data: JSON.stringify({
        '__metadata': { 'type': 'SP.Data.Travel_x0020_Request_x0020_MemosListItem' },
        'Guidance1': guidance1,
        'Guidance2': guidance2,
        'Guidance3': guidance3
        }),
    headers: {
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    success: function(data){
        alert("Success");
    },
    error: function(data){
        alert("Epic fail");
    }
});
}

  • Is "error" being fired? Have you looked at the results using the browser's F12 tools? – Mike Smith - MCT - MVP Apr 8 at 1:45
  • no error shows in the developer tool – OLA Apr 8 at 1:46
  • What's the returned status code shown in the F12 tools? Or is it returning at all? – Mike Smith - MCT - MVP Apr 8 at 1:50
  • data is being inserted into the list but no status code is being showed. – OLA Apr 8 at 1:52
  • 1
    Which version of jQuery are you using? Is this in an App or a Content Editor web part, or something else? – Mike Smith - MCT - MVP Apr 8 at 2:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.