Similar function for jquery.ajax in angular2/ionic2

I have this piece of jQuery code that works fine cross-origin:

jQuery.ajax({
    url: "http://example.appspot.com/rest/app",
    type: "POST",        
    dataType: 'jsonp',
    jsonp: 'jsonp',
    data: JSON.stringify({"foo":"bar"}),
    contentType: "application/json; charset=utf-8",
    success: function (response) {
        console.log("success");
    },
    error: function (response) {
        console.log("failed");
    }
});

I’m a novice to ionic2. I’m trying to convert this to Angular2/ionic2 code but there is no success.

Is there any similar function for jquery.ajax in angular2/ionic2.
I’m not getting how to deal with the above code in angular2/ionic2 using this.http.get or this.http.post or this.jsonp.request.

Any help appreciated.

Thanks in advance.

You might do something like this:

	    let headers = new Headers();
	    headers.append('Content-Type', 'application/json');

	    this.http.post('http://example.appspot.com/rest/app', JSON.stringify({"foo":"bar"}), {headers: headers})
	      .subscribe(res => {
                console.log("success");
	      }, (err) => {
	      	console.log("failed");
	      });

Make sure to import both Http and Headers.

In such transition, it’s worthwhile to understand the difference between promise(jq.ajax) and observable(http.post)

hi @itlr, I am new to angular2/ionic2 and confuesd with observables and promises… and went through suggested video by you earlier… but I didn’t make out to work with observables for jsonp

@joshmorony no success… I followed what suggested by you…