-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
Hi,
This is my JSONP call.
import {Injectable} from 'angular2/core';
//import {CONTENTS} from './mock-searchdata';
import {Ajaxconfig} from './ajaxconfig';
import {Http,Jsonp, Response,URLSearchParams} from 'angular2/http';
import {Observable} from 'rxjs/Observable';@Injectable()
export class SearchService {
constructor (private jsonp: Jsonp) {}
//private url = Ajaxconfig.getBaseURL() + "/typeahead?q=";
private url = "http://localhost:3030/solr/ens/typeahead?";
getSearchData(searchQuery: string){
//return CONTENTS;
//return this.http.get(this.url+searchQuery);/*return this.http.get(this.url+searchQuery) .map(res => res.json().data) .do(data => console.log(data)) // eyeball results in the console .catch(this.handleError);*/ var params = new URLSearchParams(); params.set('q', searchQuery); // the user's search value params.set('wt', 'json'); return this.jsonp.get(this.url,{ search: params }).subscribe(response => console.log(response.json()),error=>console.log(error),()=>console.log("completed"));//.map(request => <string[]> request.json()[1]); } private handleError (error: Response) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.error(error); return Observable.throw(error.json().error || 'Server error'); }}
I am able to see proper success call in chrome network tab i.e status 200.
I can also see the response from network tab, but in console I get error.
=============API Response=============
{
"responseHeader":{
"status":0,
"QTime":1},
"response":{"numFound":62,"start":0,"docs":[
{
"title_s":"Samantha Who?"},
{
"title_s":"Afro Samurai"},
{
"title_s":"Afro Samurai"},
{
"title_s":"Same Sex America"},
{
"title_s":"Same Sex America"},
{
"title_s":"Sam & Cat #124"},
{
"title_s":"Sam & Cat #125"},
{
"title_s":"Sam & Cat #999"},
{
"title_s":"Samantha Who? Season 1"},
{
"title_s":"Samantha Who? Season 2"}]
}}
Please let me know what is missing since its a cors ajax call, I am using JSONP

