0

I tried to get a value from a HTML table to Node JS. I tried like following,

HTML

<table class="table">
   {{#images}}
   <tr>
       <td><a href="/deleteImage" class="btn btn-danger" title="Clear All">X</a><label value={{imgURL}} name="imageID">{{imgURL}}</label>
       </td>
       <td><img src={{imgURL}} alt="Mountain View" style="width:228px;height:340px"></td>
   </tr>
   {{/images}}
</table>

app.js

app.get('/deleteImage', function (req, res) {
  images.removeImage(req.body.imageID, function (err, result) {
    if (err) return res.json(err);
    images.getImages(function (err, images) {
        if (err) return res.json(err);
        var msg = 'Deleted ' + result.affectedRows + ' rows.';
        res.render('delete_image.html', {images: images, msg: msg});
    });
  });
});

I tried to read the imageID from the HTML like above. But It's undefined. How can I fix this.

Thanks in Advance!

1
  • 1
    A common way to pass parameters to the server are by putting parameters on the URL such as /deleteImage?id=123. Then on your node server, you can get the id=123 out of the URL. If you don't want to actually load a new web page when sending the request, then make the request an Ajax call. Commented Mar 11, 2015 at 4:05

1 Answer 1

1

you can try

<a href="/deleteImage?imageID={{imgURL}}" class="btn btn-danger" title="Clear All">X</a>

and use req.query.imageID instead

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.