API that is used by SharePoint-hosted applications

After tirelessly searching through various resources and attempting different code snippets from Microsoft Documentation, I am still unable to identify my mistake. I am working on updating a field named DispatchStatus in a list called Schedule Orders using REST. Unfortunately, every attempt I make results in either an undefined success function with the field remaining unchanged or an error message like this:

{"readyState":4,"responseText":"404 NOT FOUND","statusText":"NOT FOUND"}

Here is the code I currently have:

function updateDelivery(id) {
    var url = "_api/web/lists/GetByTitle('Scheduled Orders')/items(" + id + ")"
    var itemMetadata = {
      '__metadata': {
          'type': getListItemType('Scheduled Orders')
      },
      'DispatchStatus': document.getElementById(id).value
  };
  updateL(url, itemMetadata, checkresult);
}
function updateItem(url, itemMetadata, callback) {
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        data: JSON.stringify(itemMetadata),
        type: 'POST',
        contentType: 'application/json;odata=verbose',
        headers: {
            'X-HTTP-Method': 'MERGE',
            'X-RequestDigest': $("#__REQUESTDIGEST").val(),
            'Accept': 'application/json;odata=verbose',
            'IF-MATCH': '*'
        },
        success: function (data) {
            callback(data);
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }
    });
}
function getListItemType(name) {
    var ret = "";
    var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + name + "')?$select=ListItemEntityTypeFullName"
    $.ajax({
        url: url,
        method: "GET",
        async: false,
        headers: {
            "Accept": "application/json; odata=verbose"
        },
        success: function (data) {
            ret = data.d.ListItemEntityTypeFullName
        },
        error: function (error) {
           alert(JSON.stringify(error));
        }
    });    
    return ret;
}

It feels like updating a list item should be a straightforward task. Am I overlooking essential data? Do I need to transfer all previous data into the item? Or should I approach item updating in a different manner?

Answer №1

After some investigation, I managed to solve the issue. It turns out that the code was functioning properly all along, but Internet Explorer had trouble recognizing it.

var a = b = c = d = "";

This caused a problem in IE, where it seemed like the code wasn't working due to the way the values were being assigned. However, when I checked the application in Chrome, everything was running smoothly. It became clear that the issue lied with the browser itself. After identifying and fixing the problem, the code finally functioned properly in IE. It's frustrating how IE can cause things to break while other browsers work perfectly fine. I'm still puzzled as to why only var c was affected in IE, while the rest of the code worked without any issues. The inconsistencies between browsers remains a mystery.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Optimal method for submitting AJAX data through a form and retrieving the response value

I have a small form that needs to dynamically update values in select boxes using jQuery on change events. Here is the code snippet: $("form#updateclient select").change(function(){ // use one selector for all 3 selects $.post("inc/process-update.php" ...

Detecting and removing any duplicate entries in an array, then continually updating and storing the modified array in localstorage using JavaScript

I'm facing an issue with the function I have for pushing data into an array and saving it in local storage. The problem is that the function adds the data to the array/local storage even if the same profileID already exists. I want a solution that che ...

Delete the tag that comes before

Is there a specific tag like: <p id="name" onclick="javascript:var ele=context(this);">sumtext here</p><br> <p id="name" onclick="javascript:var ele=context(this);">newtext here</p><br> <script ...

What could be causing my JSON product list to not load properly?

My list is not loading and I can't figure out why. I've included my json, jquery, and HTML below. The console isn't showing any errors, but the list is still blank. Any help would be greatly appreciated as I am new to working with json. Than ...

Ways to incorporate the point count divided by a specified value onto a map

I am working with Mapbox GL JS and I have a specific requirement to display the number of markers in a cluster divided by 10 on the map. To achieve this, I am utilizing the point_count and point_count_abbreviated attributes in the code snippet below: map ...

What could be causing my ajax file uploader to malfunction?

I am currently working on building an AJAX file upload module. Below is a snippet of the code I have been using: //creating a form for uploading files via AJAX FileUploader.prototype.createForm = function() { // creating a new form var form = docu ...

When Jquery JSON DOM fails to load data

I've been trying to implement this functionality on my website by following various tutorials, but I am facing an issue where the data is not displaying anywhere. Initially, it was showing the return value of json_encode, but now it's not even do ...

Unable to upload any further verification documents to Stripe Connect bank account in order to activate payouts

Query - Which specific parameters should I use to generate the correct token for updating my Stripe bank account in order to activate payouts? I've attempted to activate payouts for my Stripe bank account by using a test routing and account number (t ...

PyScript <script type="py-editor"> Issue: SharedArrayBuffer cannot be used in an insecure environment

I am currently using PyScript to execute a basic Python script within my HTML file in order to show a pandas DataFrame. However, upon loading the page in the browser and attempting to run the code block by clicking the run button, I encounter an error rela ...

What is the preferred method for verifying AJAX success when the server's response is either true or false?

My server response can be either true or false. I've been attempting to determine how to check for success based on the returned value being true or false using the script below: $('form[data-async]').on('submit', function(event) ...

Retrieve a unified data array from the provided data source

Below is a snapshot of my data const data = [{"amount": "600,000", "cover": null, "id": "1", "img": "636e56de36301.1.png", "make": "bmw", "model": "bmw ...

Creating a custom URL following a redirect in Contact Form 7 to ensure a unique

This is the code I am currently using: <script type="text/javascript> document.addEventListener( 'wpcf7mailsent', function( event ) { location = 'https://www.example.com/thank-you/'; }, false ); </script> With this ...

Building a matrix-esque table using d3.js reminiscent of HTML tables

I would like to generate a table resembling a matrix without numerical values. 1. Here is an example of my database table: | CODE | STIL | SUBSTIL | PRODUS | |------|-------|----------|---------| | R | stil1 | substil1 | produs1 | | R | stil1 | s ...

Load information from several folders into a dropdown menu, dynamically updating the options based on the selected folder using AJAX and JSP

As a newcomer to AJAX, I have a specific requirement to populate data in a dropdown menu. I have two dropdowns - the first one should display the names of folders stored locally on our system, each containing different kinds of files. My task is to dynami ...

Show the chosen value from the dropdown menu on all JSP pages

I have a header.jsp file containing a dropdown box labeled "Role". This header.jsp is designed to be included in all other JSP files using a directive. Once a user logs in, they are directed to a homepage where they must select a value from the dropdown ...

What are some ways to make session variables available for sub applications?

I am currently working on setting up an API to interact with a MongoDB database, which I have integrated as a subapplication. In my server controller, I have created a session variable. However, I am facing an issue where the session variables are not be ...

Stop a hyperlink from refreshing the webpage

Currently, I am in the process of developing a responsive menu. You can view a demo of my progress on Codepen. In order to prevent the page from reloading when I click a link within the menu, I have implemented the following JavaScript code: $('nav. ...

focusing on a specialized format using the serialize() method

Following up on my previous question which was answered so promptly by Meder, there is now an additional query that has arisen while creating a reusable jQuery form submission without redirecting the user. Issue The jQuery serialize() function is applyin ...

The result of calling addEventListener is undefined

My issue lies with the addEventListener function, as it is not working correctly. I've created a function that requires an event listener to track scrolling and then execute a callback function. window.addEventListener("scroll", checkPosition); Unf ...

Adding items to an array within a jQuery each loop and performing a jQuery ajax request

I am trying to loop through an array, push the results into a JavaScript array, and then access the data outside of each loop and AJAX call. Can anyone explain how to do this? This is what I have attempted: var ides = ["2254365", "2255017", "2254288", ...