Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

335
Views
always getting one value undefined when parsing a json string and json.stringify not working properly

I'm building a website in node js express with ejs view.

I'm taking some data from an array and saving it to session storage.
then I stringify it and catch it on a function call connected to an HTML card click.
but whenever I stringify the parsed data and passed it to the data of ajax.
The API call is not happening giving an undefined error.

Here is my code:

const parsedData = JSON.parse(localStorage.getItem('myData'));
console.log(parsedData, 'parsedData');
var d = JSON.stringify(parsedData);
console.log(d, 'd');

const container = document.getElementById('s1');

parsedData.data.rows.forEach((result, idx) => {
  var pid = result.master_id;
  var session = result.session_name;
  console.log(pid, session, 'a', 'b');
  var c = { pid, session };
  console.log(c, 'csdc');
  var userData = c;

  sessionStorage.setItem('user', JSON.stringify(userData));
  console.log(userData, 'data for api');

  const card = document.createElement('div');
  card.classList = 'card';

  const content = `
          <div class="row">
             <div class="card" id="${result.master_id}" onclick="approve(this.id)" >
          
             
              <div class="card-body" id="${c}" onclick="graphApi(this.id)">
                <br>`
                ...
});

in my ejs. using this id="${c}" onclick i call this function,

function graphApi(id) {
  var json = JSON.parse(sessionStorage.getItem('user'));
  console.log(json, 'value from card');

  var data = JSON.stringify(json);

  console.log(data1, 'data1 here');

  $.ajax({
    type: 'POST',
    data: data,

    dataType: 'json',
    url: 'http://localhost:5000/graphFromcsvfile',
    success: function (data) {
      alert('success');
      console.log(data, 'graph api');
    },
    error: function (err) {
      alert('graph api failed to load');
      console.log(err);
    },
  });
}

I'm getting an ajax error in the browser saying,

responseJSON: {
  message: 'Error: WHERE parameter "pid" has invalid "undefined" value';
}
responseText: '{"message":"Error: WHERE parameter \\"pid\\" has invalid \\"undefined\\" value"}';

Regards.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!