How can I format on server side so returned AJAX is formatted in the markup?

My server will return a hollow shell of an html page. In a simple example…

<html>
  <head>
    <title>end-user</title>
  </head>
  <body>
    <div id='prnt'>
    </div>
  </body>
</html>

It then does an AJAX request to return dynamic content. Again a simple example of the content…

  <div id='chld'>
    <div id='gndcld'>
      All kinds of stuff will go in here!
    </div>
  </div>

As the end-user is a developer that will take the markup and modify it for their own specialized use, I want the HTML markup to be formatted for ease of readability, with all the indentions and new lines. So the resulting markup would look something like…

<html>
  <head>
    <title>end-user</title>
  </head>
  <body>
    <div id='prnt'>
      <div id='chld'>
        <div id='gndcld'>
          All kinds of stuff will go in here!
        </div>
      </div>
    </div>
  </body>
</html>

So far I can return the content so that the browser rendering of the markup is what I want, but the markup itself is all in one line. I’ve tried various rn type combinations that either the browser doesn’t like or it simply ignores. Is this even possible? If it is significant, the server code is C++ and I’m using plain JavaScript on the browser side. The server is a microcontroller, so there is not enough room for things like jQuery or other 3rd party libraries.

Thanks for any help you can provide.

use route parameter in the Redux Saga file

How to pass current route parameters to the saga function?

enter image description here

// Saga
 function* findOneReleaseWithFilesSaga() {
   const { productName, releaseId } = useParams()
   try {
     const releaseResponse: AxiosResponse = yield call(findOneWithFiles, releaseId)
                                                       ^^^Error Here^^^
     yield put(getAllReleasesSuccessAction(releaseResponse))
   } catch (error) {
     yield put(getAllReleasesErrorAction(error))
   }
 }

// Fetch Data
 export const findOneWithFiles = async (releaseId:string) => {
   return await Api.get(`/releases/${releaseId}/?populate=data_files`)
     .then((res) => res.data.data)
     .catch((err) => err)
 }

How can i get all GUID’s in parents and children where enabled = true

I have a need to get a list of all nodes (guid) in my json doc where the enabled key is set to true. What is the best and most effective way to read all parent nodes as well as possible children. In my case children will always be under the items key and children can also have there own children. I came up with some basic script that will check 2 levels deep but i was hoping there is a better approach which will make this more flrxible where i dont have to hardcode each level.

const enabledguid = []

function getenabled() {
  mydata.jsondoc.forEach(i => {
    if (i.enabled === true) {
      enabledguid.push(i.guid)
    }
    // Check if Parent has children
    if (i.items && i.items.length > 0){
      console.log('we have children ' + i.items.length)
        i.items.forEach(i => {
          if (i.enabled === true) {
          enabledguid.push(i.guid)
          }
          if (i.items && i.items.length > 0){
          console.log('Child has children ' + i.items.length)
            i.items.forEach(i => {
          if (i.enabled === true) {
          enabledguid.push(i.guid)
          }
            })
          }
    })
  }
  })
  console.log(enabledguid)

  
}

getenabled() 

Here is a sample of a json file

[
    {
        "enabled": true,
        "guid": "F56AAC06-D2EB-4E1C-B84D-25F72973312E",
        "name": "Farms",
        "items": [
            {
                "enabled": true,
                "guid": "144C0989-9938-4AEC-8487-094C23A5F150",
                "name": "New Farm List"
            },
            {
                "enabled": false,
                "guid": "8FBA7B0B-566E-47CD-885B-1C08B57F34F6",
                "name": "Farm Lists"
            },
            {
                "enabled": true,
                "guid": "FCD36DBD-0639-4856-A609-549BB10BEC1A",
                "name": "Farm Upload"
            },
            {
                "enabled": false,
                "guid": "4264DA98-1295-4A65-97C6-313485744B4D",
                "name": "Campaign",
                "items": [
                    {
                        "enabled": false,
                        "guid": "9CBDC6BB-5B3D-4F53-B846-AFE55F34C1E9",
                        "name": "New Campaign"
                    },
                    {
                        "enabled": true,
                        "guid": "281490B5-C67D-4238-9D52-DE1DFA373418",
                        "name": "Campaign List"
                    }
                ]
            }
        ]
    },
    {
        "enabled": true,
        "guid": "1A9127A3-7AC7-4E07-AFA0-B8F8571B1B14",
        "name": "Vendor",
        "items": [
            {
                "enabled": true,
                "guid": "6E6B4DA9-D99D-42D8-A4FE-7C7A82B9F1BE",
                "name": "Vendor List"
            },
            {
                "enabled": false,
                "guid": "63A61762-75FB-466A-8859-25E184C3E016",
                "name": "Add Vendor"
            }
        ]
    }
]

How to get Data using Mongoose

I want to get following data using Mongoose.

This is Schema structure

title: {
    type: String,
},
deadline: {
    type: Number,(day)
},
date: {
    type: Date,
    default: Date.now()
}

In above, “date” field represents start time.
start time = date
end time = date + 24 * 3600 * 1000 * deadline
I want to get data that current date is in between “start time” and “end time”
Please help me.

Validate names with accent input in javascript

I making a form to get user name and save in database.

I Need a regex that accept names with accent like Cláudio, João, Carlos, and reject Tes3, Gabriel#. I need just letters, cuz the name of people just have letters.

Already tried these regex: /[a-z u00E0-u00FC]{5,50}/i,/^[a-zA-Z]+('|-|.)[a-zA-Zs]+$/,^[A-Za-z]+$, but none worked.

Tks for reading =)

Real-time Clock showing incorrect date html/css/javascript

I’m trying to make a real time clock with this format (DD/MM/YYYY – HOUR:MIN:SEC) but it displays the wrong date.

PHOTO:

Clock

It should display the current date.


MY CODE

function display_c() {
  var refresh = 1000; // Refresh rate in milli seconds
  mytime = setTimeout('display_ct()', refresh)
}

function display_ct() {
  var x = new Date()
  var day = x.getDay()
  var month = x.getMonth()
  var year = x.getFullYear()
  var hour = x.getHours()
  var min = x.getMinutes()
  var sec = x.getSeconds()
  if (day < 10) day = "0" + day;
  if (month < 10) month = "0" + month;
  if (hour < 10) hour = "0" + hour;
  if (min < 10) min = "0" + min;
  if (sec < 10) sec = "0" + sec;
  var x1 = day + "/" + month + "/" + year + " - " + hour + ":" + min + ":" + sec;
  document.getElementById('ct').innerHTML = x1;
  display_c();
}
<html>

<head>
  <title>Lancelot</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="projetoNew.css">
  <script type="text/javascript" src="projetoNew.js"></script>
</head>

<body onload=display_ct();>
  <header>
    <div class="headerContainer header-theme">
      <a href="" class="header-logo button-theme1 header-item">Lancelot</a>
      <span id="ct"></span>
    </div>
  </header>

Second Line of Else Block Not Running [closed]

In my else block, the second line does not appear to be running. It runs setHelperText but seems to ignore setAlertValue.

  const [alertValue, setAlertValue] = useState("error");
  const [errValue, setErrorValue] = useState("Error State");
  const [helperText, setHelperText] = useState('Input "success" to remove error');

  const handleChange = (e) => {
    setErrorValue(e.target.value);

    if (e.target.value === "success") {
      setAlertValue(null);
      setHelperText("Update input to re-enable error");
    } else 
      setHelperText('Input "success" to remove error');
      setAlertValue("error"); // this line does not run
  };

  <TextField
       label="Error State"
       message="this is an ERROR message"
       alert={alertValue}
       value={errValue}
       onChange={handleChange}
       helperText={helperText}
   />

my projects functionality works with live server extension only

I just created my first calculator and it works perfectly on live server, but not directly if opening via HTML file. After placing js, css, img and audio file in separate folder and changing the path in HTML it started working, but the arrow function that serves to delete symbols still not working if opening directly. Any ideas?

  <section>
    <p>Olena's <br> calculator</p>
    <div class="container">
        <div class="pic"><img src="files/pic.png" alt="pic"></div>
        <div class="display" id="dis"></div>
            <div class="buttons">
                <div class="button" id="c">C</div>
                <div class="button" id="pro">.</div>
                <div class="button" id="larr">&larr;</div>
                <div class="button" id="sub">/</div>
                <div class="button" id="seven">7</div>
                <div class="button" id="eight">8</div>
                <div class="button" id="nine">9</div>
                <div class="button" id="mul">*</div>
                <div class="button" id="four">4</div>
                <div class="button" id="five">5</div>
                <div class="button" id="six">6</div>
                <div class="button" id="di">-</div>
                <div class="button" id="one">1</div>
                <div class="button" id="two">2</div>
                <div class="button" id="three">3</div>
                <div class="button" id="plus">+</div>
                <div class="button" id="zero">(</div>
                <div class="button" id="dblzero">0</div>
                <div class="button" id="point">)</div>
                <div class="button" id="equal">=</div>
            </div>
    </div>
</section>


<audio src="files/mixkit-plastic-bubble-click-1124.wav" id="audio"></audio>

<script src="files/index.js"></script>

buttons.map(but => {
but.addEventListener('click', (key) => {
    console.log(key.target.innerText)
    switch (key.target.innerText) {
        case 'C':  
            display.innerText = ' '
        break
        case '←':
            if (display.innerText) {
            display.innerText = display.innerText.slice(0, -1)
            break
            }
        case '=':
            try{
            display.innerText = eval(display.innerText)
            break
            } catch {
                display.innerText = 'Помилка'
                break
            }
        default:
            display.innerText += key.target.innerText 
    }
})
})

const audio = document.getElementById('audio')

document.onclick = () => audio.play();

ES6 module constructor’s scope

I’ve stumbled upon a behavior I cannot understand. Could someone, more proficient with JS, have a quick glance at it.

I apologize for posting screenshots instead of setting up a working example here, but I hope it should be enough for an expert to quickly recognize what’s reason is.

  • I have a JS class in an ES6 module
  • I pass a function to the class’ constructor
  • I attach an event handler to an HTMLElement and in this handler I expect to have this function to be accessible.

It’s accessible if I don’t use ES6 modules, I’ve checked. So the reason must be related to the ES6 modules’ scope also I suspect the shadow DOM may be related.

So at this point, line 8 the notifyController function is definedpicture of a browser's console window, function is defined.

But when the event handler is run, it’s undefined.picture of a browser's console window, function is not defined

How come?

Thank you in advance.

Iterative implementation of Binary Search

please i have a question about the Iterative implementation of Binary Search

This is the function i create in c:

int BinarySearch(int arr[], int l, int r, int x)
{
  while(l <=  r) {
      int mid = l + (r - l) / 2;
      if(arr[mid] == x)
          return mid;
      if(arr[mid] > x)
          r = mid - 1;
      else
          l = mid + 1;
  }
  return -1;
}

This is my main function :

int main()
{
    int arr[] = {1,2,3,5,16,15,20};
    int n = sizeof(arr) / sizeof(arr[0]);
    int x = 16;
    int result = BinarySearch(arr, 0, n-1, x);
    (result == -1)
        // WE CALL THIS ternary operator.
        ? printf("Element is not present in array")
        : printf("Element is present at index %d", result);
    return 0;
}

The question is: when i search 16 the function return -1.
If you see the number 16 is on the list any help please ??

JS is Concatenating instead of Adding Variables [duplicate]

I’m trying to figure out why this block of code isn’t behaving the way I’d expect. This is for a simple online financing calculator with trade in. Everything worked until I added the ‘accessories’ section to the code. Instead of returning product + accessories (e.g. $100 + $50 = $150) it’s concatenating the results (e.g. $100 + $50 = $10050). The trade in and month calculation seem to work correctly if I don’t enter any value into the accessories field.

function Calculate() {
        var months = document.querySelector("#months").value;

        var product = document.querySelector("#product").value;

        var accessories = document.querySelector("#accessories").value;

        var trade = document.querySelector("#trade").value;

        var basket = product + accessories;

        var total =  ((basket - trade) / months).toFixed(2);

        document.querySelector("#total")
                .innerHTML = "Estimated Monthly Payment: $" + total;
}

How can I loop through a Map which contains a hashmap in angularjs?

I have a Map<String(religion), Map<String(name), Person>> where Person contains Name, Age and Date – yes name is stored twice.

I return this map and store into a [] in my controller.

I’m trying to do a repeater for every entry in people and then another repeater within that for every entry in the map inside but cant access the values. I need to create a table that creates a showing the religion, person.name, person.date for every single entry

Lerna bootstrap doesn’t install symlink

I have a project and updated from node v14 (npm 6) to node LTS (npm 8.3)

Lerna bootstrap doesn’t install my dependencies as symlink.

Structure:

.X
├── lerna.json
├── package.json (My node_modules contains A and B packages)
├── packages
│   ├── A
│   │   └── package.json (install two as symlink (taking from root node_modules)- but 
│   │                     it's not working)
│   └── B
│       └── package.json
.Y
├── lerna.json
├── package.json (My node_modules contains A and B packages)
├── packages
│   ├── C
│   │   └── package.json (it should installs A and B as symlink)
│   │
│   └── D
│       └── package.json (it should installs A as symlink)

When I use node v14, lerna bootstrap install correctly but when I use v16 it’s not..