0

我目前在 smartystreets 有一个免费帐户,需要集成自动完成功能,但在使用静态值集成 API 后,它显示 CORS 问题。所以我的问题是如何解决 CORS 问题?另外,我已经尝试过 Access-Control-Allow-Origin 但这也不起作用。

另外,我还有一个问题,我想实现另外两个功能。1- 自动完成地址并在表单中填充值。2- 页面允许用户输入地址,向SmartStreets发送请求,获取响应,并与表单一起显示结果,这次为空,允许用户输入另一个地址。有关更多详细信息,请查看以下代码:

注意:我使用的前端代码是带有 Typescript 的 AngularJs。

API Integration:
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { HttpClient, HttpParams } from "@angular/common/http";
@Injectable()
export class commonservice
{
    
    constructor(private httpclient:HttpClient){

    }
    getaddressauto(): Observable<any> {
       let smartauth = new HttpParams().set('auth-id',"72018252-ad10-b627-1234-970404bfd187");
       let smarttoken = new HttpParams().set('auth-token',"xuwSg95g4y8AObhEv3hx");
       let smartsearch = new HttpParams().set('search',"Louis");
       let smartcountry = new HttpParams().set('country',"FRA");
       return this.httpclient.get('https://international-autocomplete.api.smartystreets.com/lookup?'+smartauth+'&'+smarttoken+'&'+smartsearch+'&'+smartcountry) ;
    }
}
<html>
    <head>
        <title>SmartyStreets Address Verifier</title>
    </head>
    <body>
  <div class="p-field p-col-4">
                        <label for="address">Address Line 1</label>
                        <p-autoComplete [(ngModel)]="addressautocomplete2" [suggestions]="filteredGroup" (completeMethod)="filteraddressautocomplete($event)" (onSelect)="onEndUserSelect($event)" (onClear)="onEndUserSelect(null)" field="name" [minLength]="1" formControlName="EndUserAddressLine1">
                        </p-autoComplete>
                        <div *ngFor="let addressauto of addressautocomplete">
                            <p>{{addressauto.name}}</p>
                        </div>
                    
                    </div>
</body>
</html>
4

0 回答 0