How to Send a post HTTP request to Back office

I’m using a Vue form to send data to a link and retrieve it from back.
The Problem is that the request fails to send data , showing POST http://localhost:8080/ 404 (Not Found), and i’m trying to properly send the data, using fetch or axios.

Here’s my Vue form with the script

<template>
  
<div class="ui left aligtned container">
</div>
<h1 class="ui teal header" >Gestion d'utilisateurs</h1>
<div class="ui relaxed divided list">
  <form class="ui form" @submit.prevent="SubmitForm">
      <h4 class="ui dividing header">User modificaiton</h4>
  <div class="field">
    <div class="two fields" v-for="user in users" :key="user.id">
      <div class="field">
            <label align="left" >Nom</label>
        <!-- <input type="text" name="nom" placeholder="Nom" v-bind:value="user.name" > -->
        <input type="text" name="nom" placeholder="Nom" v-model="form.nom" >
      </div>
      <div class="field" v-for="user in users" :key="user.id">
            <label align="left">Prénom</label>
        <!-- <input type="text" name="Prenom" placeholder="Prénom" v-bind:value="user.lastname"> -->
        <input type="text" name="Prenom" placeholder="Prénom" v-model="form.prenom">
      </div>
    </div>
    <div class="field" v-for="user in users" :key="user.id">
    <label align="left">Hiérarchie</label>
    <div class="fields">
      <div class="four wide field">
        <!-- <input type="text" name="hierarchie" placeholder="Hiérarchie" v-model="user.role"> -->
        <input type="number" name="hierarchie" placeholder="Hiérarchie" v-model="form.role" ref="hInput">

          <button >Update </button>
          <a class="ui button">Cancel</a>
  </form>
      </div>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      users:[],
      form: {
          nom: '',
          prenom: '',
          role: '',
            }   
    };
  },

  methods:{
    SubmitForm(){
      
      console.log('Nom: ' + this.form.nom);
      console.log('Prénom: ' + this.form.prenom);
      console.log('Hiérarchie: ' + this.form.role);

      axios.post('/', this.form).then(
      console.log('2'));
                 
    } ,
    
  },
  mounted()
    {   
        axios.get('http://localhost:8081/api/v1/users/6')
        .then(response => {(console.log(response.data))
        this.users=response.data;
        return response.name
        });
    },
};
</script>

as shown here i declare a form that contains values I want to send, then I send this form on the HTTP request

I am unable to use image as background Image in react javascript

import { useState } from 'react'
import img from './Images/bg.jpg';
export default function Home() {
  const[BackPhoto] = useState(img);
  return (
<>
<section
        style={{ backgroundImage : BackPhoto}}
      >
</section>
</>

I am a beginner and learning react js . I am making a website and I have been stuck. I want to import a image and use it as a background photo by turning it in a state.. Please solve my problem.

Operations with dates in javascript

I hope you guys can help me. I’m developing a shopping page about online courses in Elementor. These courses start every 2 months and I want to add a feature that changes the price when there are only 19 or less days left to purchase the course before it starts. I managed to solve the problem only for certain cases, for example: The course begin on february 28th and todays date is february 17th. So by using the “new Date()” object and then adding the .getDate() method, I got the current day. Then, to grab the course date, I had to use the method parseInt(“28th february”), (I’m Spanish so the number comes first). Once I had both dates I wrote an if statement saying:

if ((courseDate – currentDate) <= 19) {
Do this…
}

It works if boths dates are in the same month… But, for example, if the course begins the next month, on march 22th, it will also evaluate to true, but there are actually more than 19 days left to purchase… Any ideas about how can I solve it? I appriciate your help and time guys

How do i make the data in the input feild of my form in next js stay after refresh of the page?

I am working on a form in nextjs and i would love the data to remain the same i.e persist after the entire page as been refreshed or reloaded . Local storage doesnt work with next js , so i am looking for an alternative , i always get local storage not defined when i use it
Here is my code below

import React, { useState, useEffect, useLayoutEffect, createContext , useContext } from "react";
import { useRouter } from "next/router";
import Cookie from "js-cookie";
import { parseCookies } from "../helpers/index";
import { Formik } from "formik";
function Form() {
  
  return (
    
      <div>
     
      <form action="" >
        <section class="left">
          <div class="input-container">
            <label for="name">Full name</label>
            <input
              type="text"
             
            />
          </div>
          <div class="input-container">
            <label for="age" required>
              Mobile Number
            </label>
            <input
              type="text"
              
            />
          </div>
          <div class="input-container">
            <label for="phone">Choose password</label>
            <input
              type="text"
             
            />
          </div>
          
            
          </div>
        </section>
      </form>
      
    </div>


  );
}

export default Form;


  

THANK YOU SO MUCH

Why does my javascript variable not submit with my HTML form?

I have the following line in my JS file for a variable I have already defined;

document.getElementById("total").value = total;

I then have the following line in my HTML form which I would like to be set with the total value above;

<input type="hidden" id="total" name="total"/>

However, when I submit my form I cannot see this total value being set? I am referencing this JS file in other spots so I don’t believe it’s a referencing issue. Am I setting the variable incorrectly in the form element?

The value is just blank in my $_POST data

TIA

I am trying to connect my web page to my local server database but I am getting error ECONNREFUSED

 errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3000,
  fatal: true

I am using Mac OS and VS Code to connect to my local server. I have connected mysql workbench to VSCode as well and it is working fine. But when I try to connect it with my program it is not working. I changed the hostname from ‘localhost’ to ‘127.0.0.1’ as well still no luck. Also, I changed my port from 3306 to 3000 as it was not connecting and I got the following error

code: 'ER_ACCESS_DENIED_ERROR',
  errno: 1045,
  sqlMessage: "Access denied for user 'usersql'@'localhost' (using password: YES)",
  sqlState: '28000',
  fatal: true

My code:

const { createPool } = require('mysql')

const pool = createPool({
    host: "127.0.0.1",
    user: "usersql",
    password: "password123",
    database: "userdb",
    connectionLimit: 10,
    port: 3000
})

pool.query(`select * from userdb.New_Customer`, function(err, result, fields) {
    if (err) {
        return console.log(err);
    }
    return console.log(result);
})

Reverse a string algorithm – JavaScript

I’m trying to solve this algorithm but am getting undefined at the beginning. Can anybody explain why this is happening so I may solve it?

// Given a String S, reverse the string without reversing its individual words. Words are separated by dots.

function reverseStr(str){
    newStr="";
    for(var i=str.length;i>=0;i--){
        newStr+=str[i];
    }
    console.log(newStr);
}

reverseStr("hcum.yrev.margorp.siht.ekil.i");

Output: undefinedi.like.this.program.very.much

gruntjs – Uncaught SyntaxError: Identifier has already been declared

I am using grunt to uglify my Js code, but when I test my code in the browser I get:

Uncaught SyntaxError: Identifier has already been declared

Here is an example of the test I di:
files:

testA.js-

export const myData = {
  a: "hello",
  b: "Me",
};

testB.js-

import { myData } from "./testA.js";

const doSomething =()=>{
    console.log(myData);
}

doSomething();

uglify file:

test.min.js-

const myData = { a: "hello", b: "Me" };
import { myData } from "./testA.js";
const doSomething = () => {
    console.log(myData);
  },
  myData = (doSomething(), { a: "hello", b: "Me" });
import { myData } from "./testA.js";
const doSomething = () => {
  console.log(myData);
};
doSomething();
export { myData, myData };

As you can see myData is exported twice but the error line starts at line 2.
Is there a way to prevent grunt from creating duplicate identifiers to fix the problem?

quicktype-core: generating TypeScript interfaces that allow extra unknown properties when parsing, without throwing an exception

I’m using NPM package: https://www.npmjs.com/package/quicktype-core to generate TypeScript interfaces from JSON samples.

Here’s a simple example of the code that generates the interfaces:

const sample_object = {
    prop_a: 'value A',
    prop_b: 'value B',
};

const jsonInput = jsonInputForTargetLanguage('typescript');
await jsonInput.addSource({
    name: 'MyNewInterface',
    samples: [JSON.stringify(sample_object)],
});
const inputData = new InputData();
inputData.addInput(jsonInput);

const result = await quicktype({
    inputData,
    lang: 'typescript',
    inferDateTimes: false,
    alphabetizeProperties: true,
    inferEnums: false,
    rendererOptions: {},
});

// Display generated interface:
const generated_code = result.lines.join('n');
console.log(generated_code);

The interface that it generates works when parsing new data that ONLY contains the properties it knows about. But if you try to parse some data that contains any extra fields/properties, it throws an exception, e.g. sample data:

const sample_object = {
    prop_a: 'value A',
    prop_b: 'value B',
    new_extra_property: 'value for new_extra_property',
};

Will throw exception:

Invalid value "value for new_extra_property" for type false

How can I configure quicktype-core to generate code that will NOT throw exceptions when data contains extra unknown fields?

I’ve tried trawling through the quicktype source code, and came across a couple of rendererOptions called additionalProperties + runtimeTypecheckIgnoreUnknownProperties … but trying to set those as either true or a string doesn’t make any difference at all to the code it generates.

Setting to true (actually gives TypeScript errors for the code, even though many quicktype-option renderedOptions are actually bools, and they’ve worked for other settings):

const result = await quicktype({
    inputData,
    lang: 'typescript',
    inferDateTimes: false,
    alphabetizeProperties: true,
    inferEnums: false,
    rendererOptions: {
        additionalProperties: true,
        runtimeTypecheckIgnoreUnknownProperties: true,
    },
});

Setting a string (keeps the TypeScript checking happy):

const result = await quicktype({
    inputData,
    lang: 'typescript',
    inferDateTimes: false,
    alphabetizeProperties: true,
    inferEnums: false,
    rendererOptions: {
        additionalProperties: 'string',
        runtimeTypecheckIgnoreUnknownProperties: 'string',
    },
});

How to make custom URLs for different website states?

In my project I have a page where there are different directories inside other directories, which show and hide with “style.display=”block/none”, problem is that I cannot figure out how to save those states in an URL so they can be sent to others.

Ideally after user clicks on the button to “Show Section 1”, and then on “Show section 11” the URL becomes website.com/section1/section11 that he can share to others.

So question is, how do I save states of websites to be shared based on where in the directory the user is?

Example code:

JS

const Section1 = document.getElementById("section1");
const Section2 = document.getElementById("section2");
const Section11 = document.getElementById("section1-1");
const Section12 = document.getElementById("section1-2");

function show1(){
     Section1.style.display="block";
     Section2.style.display="none";
}

function show2(){
     Section1.style.display="none";
     Section2.style.display="block";
}


function show11(){
     Section11.style.display="block";
     Section12.style.display="none";

}

function show12(){
     Section11.style.display="none";
     Section12.style.display="block";

}

And so on...

HTML


<button onclick="show1()">Show Section 1</button>
<button onclick="show2()">Show Section 2</button>

<div id="section1" style="display: block">

     <button onclick="show11()">Show Section 11</button>
     <button onclick="show12()">Show Section 12</button>

     <div id="section1-1" style="display: block">

          <p>Some text</p>
          <button onclick="show111()">Show Section 111</button>
          <button onclick="show112()">Show Section 112</button>

     </div>

     <div id="section1-2" style="display: none">

          <p>Some text</p>
          <button onclick="show121()">Show Section 121</button>
          <button onclick="show122()">Show Section 122</button>

     </div>

</div>

<div id="section2" style="display: none">

<p>Something in here...</p>

</div>

Get deltaY from scroll event

I am trying to set up a project for use with mobile and desktop but the wheel event doesn’t work on mobile, so I need to use scroll.

I know how to get the deltaY from the Wheel event:

window.addEventListener("wheel", event => console.info(event.deltaY));

How do I get the deltaY from the Scroll event?

How to make the Select option appending with design?

Am making an select option from ajax success. The problem is that, the results are array so i need to manipulate the array with some html.

My appending code:

data = [['2022-02-01', '2022-02-02'],['2022-03-01', '2022-03-02'],['2022-04-01', '2022-04-02']]

$("#id_course").change(function () {
     $('select[id=id_intakes]').empty().prepend("<option></option>");
     $.each(data, function(index, name){
          $('select[id=id_intakes]').append(
              $('<option></option>').attr("value",name).text(name)
          )
    });
})

Just creates the select correctly, but it displays the array as it is. The dropdown contains all the three values array

['2022-02-01', '2022-02-02']
['2022-03-01', '2022-03-02']
['2022-04-01', '2022-04-02']

I need to manipulate this like

From:2022-02-01 & To:2022-02-02
From:2022-03-01 & To:2022-03-02
From:2022-04-01 & To:2022-04-02

So how to do this ?

Blob is returning empty string after creation

I have an extremely large JSON string that I need to send to my server. I encountered payloadTooLargeError when I tried sending the JSON string directly.

So, I decided to send it as a blob instead. But unfortunately, after creating the blob, the blob is returning an empty string.

Here is how I created the blob:

 let largeContentPayload = {
        data: {
            'batch_id': batchId,
            content: extremelyLargeJSON
        }
    };
    const largeContentStringified = JSON.stringify(largeContentPayload);
    const largeContentBlob = new Blob([largeContentStringified], {
        type: 'application/json;charset=utf-8'
    });
    console.log(largeContentBlob); //This is only returning size and type, the JSON string is not there
    const blobUrl = URL.createObjectURL(largeContentBlob);
    let requestBody = new FormData();
    let blob = await fetch(blobUrl).then(r => r.blob());
   

How can this be resolved?