0

I have a function that will be used when 'click' like this.

addTest(): void{

  let headers = new Headers({ 'Content-Type': 'application/json' }); 
  let body = '';
  this.http.post('http://localhost:10000/wa/dataAdd', 
                        body,
                        {headers:headers})
  .map((res: Response) => res.json())
  .subscribe( (res: Response) => { this.onRequestChange.emit({ isCreate:false}) });


}

so if i need to send string like this

[{"purchaseId":"0001","Name":"สินค้า กs","Date":"2018-06-13T00:00:00","Price":5000,"NumberQty":2,"TtlPrice":10000}]

so I taked it to body variable

let body = '[{"purchaseId":"0001","Name":"สินค้า กs","Date":"2018-06-13T00:00:00","Price":5000,"NumberQty":2,"TtlPrice":10000}]';

but my value that was sent is null

so How can I send string like this to insert to DB (SQL Server 2014)

1 Answer 1

2

From my experience this works

addTest (url:string, data:any): Observable<any>  {

  var headers = new Headers({ 'Content-Type': 'application/json'});
  var options = new RequestOptions({ headers: headers, });
  return this.http.post(url,data,options)
                .map((res: Response): Episodes => res.json())
                .catch(this.handleError);
}

with data being a json object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.