Link to home
Start Free TrialLog in
Avatar of error2013
error2013

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of error2013
error2013

ASKER

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

>>Still getting the same error:

you're writing something different.

most likely the return part is error
use browser's Inspect tool to verify the exact errors
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
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
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.
Are both fname and lname defined?
so tried exactly what I posted previously?

use var and " instead of const and '
I had to add the parameters to another file. Your change worked fine :)