За последние 24 часа нас посетили 22356 программистов и 1062 робота. Сейчас ищут 652 программиста ...

набираю http://localhost:3000/somesmart/?id=9 выдает ошибку Cannot GET /somesmart/

Тема в разделе "JavaScript и AJAX", создана пользователем riaron, 12 сен 2020.

  1. riaron

    riaron Активный пользователь

    С нами с:
    1 окт 2014
    Сообщения:
    247
    Симпатии:
    4
    набираю http://localhost:3000/somesmart/?id=9 выдает ошибку Cannot GET /somesmart/
    вот код
    Код (Javascript):
    1. app.get('/somesmart/:id', function(req, res) {
    2.     var somesmart = [];
    3.  
    4.     // Connect to MySQL database.
    5.     var connection = getMySQLConnection();
    6.     connection.connect();
    7.  
    8.     // Do the query to get data.
    9.     connection.query('SELECT `prod`,`name`,`sim`,`display`,`razresh`,`acum`,`proc`,`oper`,`sd`,`cam`,`gps`,`description`,`giroscope`,`payment`,`photo` FROM `smartphone` WHERE '+ mysql.escape(req.params.id), function(err, rows, fields) {
    10.  
    11.           if (err) {
    12.               res.status(500).json({"status_code": 500,"status_message": "internal server error"});
    13.           } else {
    14.               // Check if the result is found or not
    15.               if(rows.length==1) {
    16.                   // Create the object to save the data.
    17.                   var smart = {
    18.                     'prod':rows[0].prod,
    19.                     'name':rows[0].name,
    20.                     'sim':rows[0].sim,
    21.                     'display':rows[0].display,
    22.                     'razresh':rows[0].acum,
    23.                     'acum':rows[0].acum,
    24.                     'proc':rows[0].proc,
    25.                     'oper':rows[0].oper,
    26.                     'sd':rows[0].sd,
    27.                     'cam':rows[0].cam,
    28.                     'gps':rows[0].gps,
    29.                     'description':rows[0].description,
    30.                     'giroscope':rows[0].giroscope,
    31.                     'payment':rows[0].payment,
    32.                     'photo':rows[0].photo,
    33.                     'giroscope':rows[0].giroscope,
    34.                     'price':rows[0].price,
    35.                     'webs':rows[0].webs,
    36.                     'os':rows[0].os,
    37.                     'rom':rows[0].rom,
    38.                 }
    39.                 somesmart.push(smart);
    40.  
    41.                   // render the details.plug page.
    42.                   res.render('somesmart', {"somesmart": somesmart});
    43.               } else {
    44.                   // render not found page
    45.                   res.status(404).json({"status_code":404, "status_message": "Not found"});
    46.               }
    47.           }
    48.     });
    49.  
    50.     // Close MySQL connection
    51.     connection.end();
    52. });
    ВОТ pug
    Код (Javascript):
    1. html
    2.     head
    3.         title= 'Phones'
    4.         style
    5.             include style.css
    6.             include bootstrap.css
    7.     body
    8.         h1= 'Smartphone: '+ somesmart.name
    9.         div= "id" + somesmart.id
    10.         img(src=""+somesmart.photo+"")
    11.         div= "Производитель: " + somesmart.prod
    12.         div='Модель: ' + somesmart.name
    13.         div='Количество СИМ карт: ' + somesmart.sim
    14.         div='Диагональ дисплея: ' + somesmart.display
    15.         div='Разрешение дисплея: ' + somesmart.razresh
    16.         div='Аккумулятор: ' + somesmart.acum
    17.         div='Процессор: ' + somesmart.proc
    18.         div='Поддержка SD: ' + somesmart.sd
    19.         div='Камеры: ' + somesmart.cam
    20.         div='Датчик GPS: ' + somesmart.gps
    21.         div='Описание: ' + somesmart.description
    22.         div='Гироскоп: ' + somesmart.giroscope
    23.         div='Безконтактная оплата: ' + somesmart.payment
     
  2. ADSoft

    ADSoft Старожил

    С нами с:
    12 мар 2007
    Сообщения:
    3.823
    Симпатии:
    736
    Адрес:
    Татарстан
    Путь и маршрут не совпадают вроде
    Или урл такой должен быть
    http://localhost:3000/somesmart/9
    Либо маршрут
    /somesmart/?id=:id
     
  3. riaron

    riaron Активный пользователь

    С нами с:
    1 окт 2014
    Сообщения:
    247
    Симпатии:
    4
    Спасибо