• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

207
Views
Using ajax to convert inputs into JSON and POST to api

I am facing problem with understanding how input from tag can be converted in JSON and then posting it to my api.

My Frontend code is

<div>
    <form className="AddMentor">
      <table>
        <tr>
          <td> <label>MentorID<input type="text" name="MentorID" /></label> </td> 
          <td> <label>MentorName<input type="text" name="MentorNAME" /></label> </td>
          <td> <label>MentorEMAIL<input type="text" name="MentorEMAIL" /></label> </td> 
          <td> <label>MentorPH<input type="text" name="MentorPH" /></label> </td>
          <td> <label>MentorLINKEDIN<input type="text" name="MentorLINKEDIN" /></label></td>
          <td> <label>MentorPM<input type="text" name="MentorPM" /> </label> </td>
        </tr>
      </table>
    
    <button  type="submit" id="save">Add Mentor</button>
    </form>
</div>

And MY api code is

//ADD MENTOR API
router.route('/MentorEle').post((request,response)=>{

    let Mentor = {...request.body}

    dboperations.addMentor(Mentor).then(result => {
       response.json(result);
    })
})

I tried this for converting it into JSON and POSTING to my api

$(document).on('click', '#save', function(event) {
    event.preventDefault();
    var data = $('tr').map(function() {
        var obj = {};
        $(this).find('input, select').each(function() {
            obj[this.name] = $(this).val();
        });
        return obj;
    }).get();
    
    console.log(JSON.stringify(data));
});

It didn't work unfortunately, I faced several errors and the current error is

Module not found: Error: Cannot find file: 'node-jquery.js' does not match the corresponding name on disk: '.\node_modules\jquery\lib\jQuery'.

please anyone help me with this code or ajax approach of it

about 3 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error