How to send a JSON object from NODE JS to JQUERY
I am develoing a weather application using NodeJS server which sends a city from html to NodeJS using /POST but I want to send JSON object back to HTML/JQUERY. I've tried working with cookies but it Did'nt worked out. Errors like "module not found" or "cannot import" are common, even a shows "GET http://localhost:9000/ 404 (Not Found)".
Thanks for your Kind Help.
See also questions close to this topic
-
getColumnDefs() method is not present in gridApi in ag- grid
I am trying to get column definition in ag grid in angular 10. I am using below code using gridApi:
console.log(this.gridOptions.api.getColumnDefs());
But i am getting below error.
Property 'getColumnDefs' does not exist on type 'GridApi'. Did you mean 'setColumnDefs'?
even in gridApi.d.ts, getColumnDefs() method is not available. But in ag grid documentation, it says this is the method.
i am using "@ag-grid-enterprise/all-modules": "^24.1.0", and angular 10.0.4.
Please suggest
-
jQuery bind method does not work as expected
I need to do different actions for a select dropdown if it is selected or not! I tried this code which is working good on JSFiddle but It doesn't work within my project which is a checkout form of WooCommerce:
<select name="my_datepicker" id="my_datepicker" class="select valid" data-placeholder="Please select" aria-invalid="false"> <option value="select">Please select</option> <option value="11th December">11th December</option> <option value="12th December">12th December</option> </select>
jQuery(document).ready( function(){ jQuery("#my_datepicker").bind('change', function () { if(jQuery(this).val() != "select"){ alert('Something is selected!'); }else{ alert('Nothing is selected!'); } }); jQuery("#my_datepicker").trigger('change'); });
In my project
alert('Nothing is selected!');
works on page load as expected but after changing select options nothing happens! Even when I choose<option value="select">Please select</option>
again, it's related alert does not appear. Can you please guide me about this issue? -
How to Set Style to image pattern on mapbox GL
Hi i'm creating bus and subway routing using mapbox and react - i need different color for my pattern that drawing line on the map you can see my sample pattern on image below
as you can see pattern has static color (green) i need to set this color dynamically with hex code that return from server.
if wrote function for get pattern
getPattern(type, section_type, index, line_name) { if (section_type === routingTypes.METRO) { switch (line_name) { case '1': return pattern_metro_1; case '2': return pattern_metro_1; case '3': return [pattern_metro_1, '#00B8F8']; case '4': return '<img src={pattern_metro_1} style='border: 3px solid green' />'; case '5': return pattern_metro_1; case '6': return pattern_metro_1; case '7': return pattern_metro_1; default: return pattern_metro_1; } } }
as you can see all cases are static pattern image but i need some thing like case 3 that i set image and pattern and image fill with that color. also i tried case 4 but it doesn't work either.
-
how do you echo data from a mysqli database?
can anyone help me with this, here is my code:
<?php echo 'User Posts'; $userposts = ( SELECT posttxt, postimg FROM posts WHERE post_id = $user->data()->id ); echo ($userposts);
-
Can anyone here give me hint how to convert this code to bootstrap 4 language?
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> <style> .navbar-custom { background-color:rgb(128 128 128 / 18%); height:48px; width:100% } .close{ margin-bottom: 40px; } h2{ margin-top: 35px; margin-left: 30px; } /* .logo1{ margin-bottom: 120px; } */ .container-fluid { max-width: 100%; padding-right:0; padding-left:0; margin-right:0; margin-left:0 } html, body { margin: 0; position: relative; width: 100%; right:0; padding-right: 0px!important; margin-right: 0px!important; width: 100vw; overflow-x: hidden; } .row row-cols-1{ width: 100%; right: 0; } </style> </head> <body> <div class="container-fluid"> <nav class="navbar navbar-custom"> <a class="navbar-brand" href="#"> <div class="mt-0 "> <img src="logo.png" class="logo1" alt="logo" style="width:50px;"></div> </a> <button type="button" class="close" aria-label="Close"> <span aria-hidden="true">×</span> </button> </nav> </div> <h2>Do you have Fever above 101.4?</h2> <div class="mx-auto mt-5" style="width:150px"> <img src="fever.png" class="logo1" alt="logo" style="width:200px;"> </div> <br> <div class="row row-cols-1"> <div class="col"><button type="button" class="btn btn-primary btn-block mt-5">Yes,I do</button></div> <div class="col"> <button type="button" class="btn btn-primary btn-block mt-2">No, I don't</button></div> </div> </body> </html>
This code is written in ordinary html and css and a few bootstrap,My code lacks some bootstrap theme. I need it to be converted to bootstrap 4 so that everything in it resembles to bootstrap 4.Bootstrap gives your website responsiveness which is able to work perfectly fine on mobile devices and on tablets. can anyone tell me or convert this code to bootstrap 4 language?
-
How to have multiple users control relay board webpage and show active state?
I made (scrapped together) a webpage with python/flask/javascript that has 4 buttons. each button turns on 1 relay and turns of the other 3. The relay board is connected via I2C to a Rpi. The "in use"-button is highlighted, and i use localstorage to show a text which relay is active after a page reload. I would now like to show the status of the active button/relay on a different pc. (there is no readback from the i2c board.)
Do i use a cookie for this or a file on the server that states the active relay ? and how do i show this on an html page ?
how do i force a website refresh if the active status changes or do i just let it refresh ?
I'm a noob when it comes to programming, so any help or pointers would be great. regards Jan.
-
date.toString throwing error "Expected 0 but got 1"
Hi i need to parse the date object into yyyy/mm format but i'm unable to do so.
let date = new Date(row.month_date); cell['date'] = date.toString('yyyy-MMMM'); cell['v'] = cell['date'];
Above code is throwing error Expected 0 but got 1, can anyone please tell me what i am missing here ?
-
Node.js application starts never ending processes in production
I am hosting a node.js application on cPanel. It is nothing but simple RESTful web APIs using express which include CRUD. The issue that I am facing is that the number of processes are getting increased by time, means some of the previous processes are never ending and application keeps on adding until the point where my server reaches resource limit and all the applications stop working. cPanel actually doesn't have a way to
console.log()
any errors which I am writing the code to do from inside my application. All I can see is the main domain from where the processes are stemming.I am writing this in my terminal to check processes
ps -ef | grep node
-
Catch result from Python-shell (Node js ) in real time not at the end of execution
i try to catch result from the execution of my Python script on node in real time . My problem is he give me the result but only when he finished the execution ..
my node code is :
let options = { mode: 'text', pythonOptions: ['-u'], // get print results in real-time scriptPath: '', //If you are having python_test.py script in same folder, then it's optional. args: [fileName, cryptedName, finalMdp] //An argument which can be accessed in the script using sys.argv[1] } b1.update(100) PythonShell.run('crypto.py', options, (err, result)=>{ b1.update(140) if (err) throw err; b1.update(160) console.log('results: %j', result) b1.update(200)
and my Python code is like this :
from progress.bar import Bar import sys from hashlib import sha256 fichierDeBAse = sys.argv[1] newName = sys.argv[2] mdp = sys.argv[3] keys = sha256(mdp.encode('UTF-8')).digest() bar = Bar('Processing', max=100) for i in range(100): with open(fichierDeBAse ,'rb') as f_entree: print(bar,flush=True) with open(newName ,'wb') as f_sortie: i=0 while f_entree.peek(): c = ord(f_entree.read(1)) j = i%len(keys) b = bytes([c^keys[j]]) f_sortie.write(b) i= i+1 bar.next() bar.finish()
-
I need an experienced perspective about Helper class
I started learning javascript and nodejs. I use express for HTTP handling and I coded a class for checking missing parts and I am wondering, is it the correct way.
What the checkEmpty method doing is checking missing parts and returns an array that missing parts. Here is my helper class;
class Helper{ /** * @param {String Array} areas * @param {Object} data * @returns {Array} */ checkEmpty(areas, data){ let result = []; areas.forEach(area => { if (!data[area]) { result.push(area); } }); return result; } } module.exports = Helper;
I create middleware for register request and I want to check is required areas empty or not. I send what has to check and my request body as parameters.
const Helper = require('../helper/Helper'); module.exports = function(req, res, next){ let result = new Helper().checkEmpty(['name', 'email', 'password'], req.body); if(result.length > 0){ res.json({ error: true, message: 'Missing part(s)', empty: result }); }else{ next(); } };
Output looks like;
{ "error": true, "message": "Missing part(s)", "empty": [ "name", "password" ] }
So as I said, I am wondering, is it the correct way to do that, and if it is correct then how file structure has to be, or is there a tool already in express or nodejs?
-
The default route is not added by rmnet interface when the WiFi interfaces are UP
I'm developing a router, that uses a sim-card for the WAN connection. When the rmnet interface is up and WiFi interfaces are down, the default route is created successfully:
root@OpenWrt:/# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 10.59.127.70 0.0.0.0 UG 0 0 0 rmnet_data0
But when the WiFi interfaces are up as well, the default route is absent in the routing table. Of course, I can add it manually and 'ping' the network, but it is not a solution.
I can't even imagine where the problem can be.
I will be very grateful for any ideas and advice. Thank you in advance.
-
Vanilla php files in subfolder with laravel - page not found error
I have a laravel app: https://laravel-app.com
I want to serve custom pages from a folder on the same domain https:laravel-app.com/player/player.php
I have set the .htaccess file
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /player/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /player/player.php [L] </IfModule>
But when I try and navigate to that page by using this direct url: https:laravel-app.com/player/player.php
I get the laravel routing error: sorry, the page could not be found
Can someone explain how to get around this?
-
Controller is not callable while route request for get page in symfony framework
I am beginner in symfony framework, i used to given path in the routes.yaml file in the config folder, but when i used to render this route this show me an error.
Error:- The controller for URI "/test" is not callable: Controller "Src\Controller\TestController" does neither exist as service nor as class.
Please help me to find my mistake.
routes.yaml
index: path: /test controller: Src\Controller\TestController::index
TestController.php
<?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class TestController extends AbstractController { public function index(): Response { return $this->render('test.html.twig'); } }
test.html.twig
<h1> Test </h1>