I'm trying to send a TypeScript class with the jQuery post method. And everything is working well, but there is one point I'm trying to fix.
Lets say i got the model below.
export class TestModel{
private id: string;
private username: string;
constructor(id: string, username: string) {
this.id= loginName;
this.username= password;
}
IsValid(): boolean {
return true;
}
}
And to post it i got this function:
var testModel = new TestModel("test1", "test2");
$.ajax({
url: "MyUrl",
type: "POST",
data: testModel,
});
When I look to the network request the folowing information is post:
id: test1
username: test2
IsValid: true
The only things i want to post is the id and username, the IsValid method is only to validate this model, like are all fields filled in, when it's an email field check an email filled in etc.
So my question is, what is the solution to only send the id and username, without any other functions? (if this is possible ofcourse :)).
Thanks for your help, Stefan