Error - Expected 2 Arguments but got 0

I am having the following error with this code:

insertData(fname, lname) {
    const body = JSON.stringify({firstName: fname, lastName: lname});
}

Open in new window


Error: Expected 2 Arguments but got 0

How can I fix this?
LVL 1
error2013Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
check JSON.stringify syntax

JSON.stringify()
https://www.w3schools.com/js/js_json_stringify.asp

hence try:

function insertData(fname, lname) {
 var body = JSON.stringify({"firstName": fname, "lastName": lname});
 return body;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
error2013Author Commented:
Still getting the same error:

  insertData(fname, lname) {
    const body = JSON.stringify({'firstName': fname, 'lastName': lname});
    return this.http.post('http://myurl/insert.php', body, httpOptions);
  }

Open in new window

0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>Still getting the same error:

you're writing something different.

most likely the return part is error
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
use browser's Inspect tool to verify the exact errors
0
error2013Author Commented:
The errors are pointing to this line:

const body = JSON.stringify({'firstName': fname, 'lastName': lname});

Open in new window


And only appeared when I added fname and lname to the function
0
SteHCommented:
Where do you exactly get the error? in the JSON line, or when calling the function?
In the latter case look where this function is called and if always with two parameters
0
error2013Author Commented:
ref: 'use browser's Inspect tool to verify the exact errors'

I'm using typescript and code won't compile so I won't get to the browser till I can compile it.
0
SteHCommented:
Are both fname and lname defined?
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
so tried exactly what I posted previously?

use var and " instead of const and '
0
error2013Author Commented:
I had to add the parameters to another file. Your change worked fine :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.