Using .substr method interferes with the functionality of the alert method

I've been struggling to extract the hours and minutes from a Microsoft JSON string. Despite reading through numerous articles, including How do I format a Microsoft JSON date?, I have not been successful. Even when attempting to implement the example code provided.

However, the alert function does not seem to work. I am unsure of what mistake I may be making or what crucial detail I might be overlooking. The relevant portion of the code is as follows:

$.ajax({
  type: "GET",
  url: "/TrainActivity/GetDelayDataForEditing/" + "?delayId=" + delId,
  dataType: 'json',
  //data: delId,
  success: function(data) {
    //data = JSON.stringify(data);
    //$("#myDivID").text(JSON.stringify(data));
    //var delayId = delId;

    modal.find('');
    //The following code snippet is based on the Stack Overflow article but it seems to disrupt the alert
    var date = new Date(parseInt(data.beginDelayDateTime.substr(6)));

    //var date = data.beginDelayDateTime.substr(6);
    //var date = new Date(parseInt(jsonDate.substr(6)));

    //this date is okay
    //var date = new Date();
    var unparsedDate = moment(data.beginDelayDateTime);
    var parsedDate = new Date(unparsedDate);
    var hours = parsedDate.getHours;
    var minutes = parsedDate.getMinutes;
    var timeToDisplay = hours + ":" + minutes;
    //var timeToDisplay = JSON.stringify(hours) + ":" + JSON.stringify(minutes);

    alert("Success " +
      //"\ntest date: " + date +
      "\nunparsed date: " + unparsedDate +
      "\nParsed date: " + parsedDate +
      "\nDisplay time: " + timeToDisplay +
      "\nbegin Delay time: " + data.BeginDelayDateTime
    );

    //$('#delays-grid').data('kendoGrid').dataSource.read();
    //$("#delayAddModal").modal("hide");

  },
  error: function() {
    alert("error in Delay Edit");
  }
});

//modal.find(".modal-body").text("Edit the Delay at " + name + " with id " + delId);
modal.find(".modal-footer #delayEditButton").data("guid", delId);
});

The value stored in data.beginDelayDateTime is "/Date(1531958520000)/" and this value displays in the alert without any issues.

Answer №1

The issue was resolved by fixing a typo error that epascarello highlighted - BeginDelayDateTime is not the same as beginDelayDateTime. By rectifying the spelling mistake, the problem was solved and now the Microsoft JSON date string is being parsed accurately. Thank you to everyone who offered their assistance.

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

Enhance the functionality of your Rails application by implementing Ajax or jQuery to asynchronously load table elements separately from the page

Currently, I am facing an issue with a page that displays a list of user sites. The problem lies in the fact that I am making an API call for each site to check its status, which is causing the page to load very slowly. To address this issue, I would like ...

One of the functionalities is not functioning properly: either the validation or the AJAX

My validation code was working fine until I added some ajax code. Now, when I include the onclick="return chk()" in the submit input field, the validation code stops working. But if I remove it, the ajax code doesn't work. How can I resolve this issue ...

struggling to locate path in Node.js REST API using Express and ES6 classes

I'm currently setting up a RESTful API using Node.js, and I've opted to utilize ES6 classes for the task. This is how my app.js file appears: const express = require("express"); const morgan = require("morgan"); const bodyParser = require("body- ...

Error message indicating unauthorized access while trying to implement Backbone with Slim framework and Tuupola basic authentication

I've been working on connecting my Backbone app with my server API (using Slim) and have implemented Tuppola / Basic Auth Middleware to handle authentication. The setup is fairly simple, as I'm just trying to make it work. When I access the serv ...

The status of "Checked" has now been set to untrue

As a beginner, I am struggling to understand how the value changes in my code. Here is a screenshot of the Material UI switch: https://i.sstatic.net/UCn2T.png In the provided code snippet, the value event.target.checked is coming from the following Switch ...

What are the fundamentals of type conversion in struts2?

In my struts.xml file, I have the following code: <s:textfield id="thresholdParameter_1" name="gmathreshold.distinctBnumberRatio"> </s:textfield></td> The gmathreshold is a bean with a member variable distinctBnumberRatio which is a ...

Identifying duplicated video duration data associated with videoIds in asynchronous calls using Youtube API v3

I've encountered an issue with the asynchronous methods that retrieve and display all vidDuration values followed by the corresponding viewCount values for each videoId. The problem arises when the vidDuration value repeats only the last received one ...

Using JSON queries to filter results in Thunder Client

Currently, I am conducting tests on HTTP responses using Thunder Client within VS Code. The HTTP response I am receiving is as follows: { "currencies": [ { "name": "Btc", "count": ...

JavaScript design not aligning

I'm currently attempting to find a pattern that includes the pipe (|) operator. Here is the code I've used to match the pattern: var format = /[ \\|]/; // This is the pattern for matching the pipe pattern if ("Near raghavendra temple ...

Firefox Cookie Expiry Date Automatically Set to One Week in Default Settings

I recently encountered an issue while trying to create a cookie that would persist for a year. Interestingly, the code I used worked perfectly on Chrome, as I could verify by checking the "Storage" in the dev tools. However, when I tried the same code on F ...

Ways to showcase the chosen image from the input field?

Can someone help me with an issue I'm having regarding displaying selected images? Every time I try, I encounter this error message: Not allowed to load local resource: Any suggestions or insights into why this might be happening? <input type=&a ...

Discovering the selected option's value in a dropdown and utilizing it to search through an array for data to fill another input

Is there a way to utilize the value of a select input option, created by a forEach loop, to extract the value of another property in the same array object and assign it as the value of a different input field? Apologies if this seems verbose or has been a ...

Lunar - incorporate route parameter into DOM query_operation

Is there a way to take a route parameter and use it to trigger a click event on a DOM element? The issue is that onBeforeAction is called before the DOM is fully loaded. Any suggestions on how to solve this problem? JS onBeforeAction: function(){ var ...

Both Google Chrome and Firefox are recognizing the Binance WSS api url as an HTTPS connection

My attempt to execute the code from my Chrome browser was unsuccessful. import io from 'socket.io-client'; const socket = io('wss://stream.binance.com:9443'); socket.on('connect', () => { console.log('binance [so ...

What is the most efficient way to print multiple JSON arrays simultaneously?

When looping through a database using an array, the following code snippet is used: $checkedProducts = $request->input('products'); $p = null; foreach($checkedProducts as $checkedProduct){ $p .= DB::table('products')->where( ...

What is the proper way to incorporate the "pdf" package into a TypeScript project?

I recently installed pdf and its types using the following command: npm install --save pdf @types/pdf However, I am struggling to find any documentation on how to actually use this package. When I try the following code: import {PDFJS} from 'pdf&ap ...

Using MongoDB Object as middleware in Express applications

I’m facing issues trying to access the "DB" database object that gets created when the MongoDB client module establishes a connection with my MongoDB database. Currently, I am encountering an error indicating that in data.js, 'db' is not defin ...

Utilizing Next.js to create dynamic routes and static builds incorporating unique ID values within the URL paths

Is there a way to create a page in Next.js where I can extract the ID from the URL in a dynamic route and use it for a static build without having to predefine all possible values of the ID in getStaticProps()? For example, the URL is as follows: localhost ...

Generating a JavaScript JSON object by iterating through a JSP bean with the help of JSTL's c:forEach

Two Java classes are defined as follows: public class Abc{ private List<SomeOtherClass> someClass; private String k; private String m; } public class SomeOtherClass{ private String a; private String b; private String c; } On a ...

Error detected in JSON parsing

I keep encountering a json parse error Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 2.) This indicates that there is an issue in the jSON response. What's stra ...