When i try to submit data showing an error

below my service code

public login(loginRequest:LoginRequest):Observable<AuthResponse> {
		const myHeaders = new HttpHeaders({'Content-Type':'application/json', 'Accept':'application/json'});
		return this.http.post<AuthResponse>(this.config.apiBase + '/login', JSON.stringify(loginRequest), {headers: myHeaders})
        .concatMap(data => {
            return Observable.of(data);

this is my signin code

singIn() {
		if(this.credentials.login.length == 0 || this.credentials.password.length == 0) {
			this.tosatService.showToast('Phone or Password cannot be empty!');
		} else {
			this.tosatService.presentLoading('Logging in');
			let subscription:Subscription = this.service.login(this.credentials).subscribe(data => {
				let authResponse:AuthResponse = data;
				window.localStorage.setItem('api_key', authResponse.token);
				window.localStorage.setItem('user', JSON.stringify(authResponse.user));
			}, err=> {
				this.tosatService.presentErrorAlert("Unable to login with provided credentials");

this is my model.ts

export class LoginRequest {
	login: string;
	password: string;
	constructor(login: string, password: string) {
        this.login = login;
		this.password = password;

when i trying to submit data to the server showing this error
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://mydomain.com/demo/append/index.php/login. (Reason: CORS request did not succeed

how can i fix this issue
please help me out
thanks in advance

Search the forum using the keyword ‘CORS’.

1 Like