2016-03-23 37 views
0

Merhaba her zaman bana hata alıyorum.İyonik 2 Http POST Metodu HATA

bu benim json tip

{ 
“username”:”user”, 
"password":”pass" 
} 

olan bu ben bu çözebilir nasıl kod

import {Page, NavController} from 'ionic-angular'; 
import {Http, Headers, RequestOptions} from 'angular2/http'; 
import 'rxjs/Rx'; 
@Page({ 
    templateUrl: 'build/pages/home/home.html' 
}) 
export class HomePage { 
    constructor(http: Http, nav: NavController) { 
    this.http = http; 
    this.makePostRequest(); 
    } 

    makePostRequest() { 

    var headers = new Headers(); 
    headers.append('Content-Type', 'application/json'); 
    this.http.post('url', 
     JSON.stringify({ username: 'admin', password: 'a' }), 
     { headers: headers }) 
     .map((res: Response) => res.json()) 
     .subscribe((res) => console.log("res", res)); 

    } 

} 

hata Günlüğü

4  236980 log  DEVICE READY FIRED AFTER, 1437, ms 
5  237420 group EXCEPTION: [object Object] 
6  237426 error EXCEPTION: [object Object] 
7  237431 error STACKTRACE: 
8  237433 error  
9  237435 groupEnd 
10 237525 error Uncaught #<Response>, http://192.168.1.13:8100/build/js/app.bundle.js, Line: 7834 

olduğunu.?

XMLHttpRequest http://url/login/ yükleyemiyor:

Bunun bir çapraz menşe sorun var gibi görünüyor tarayıcısı

Failed to load resource: the server responded with a status of 403 (Forbidden) 
(index):1 XMLHttpRequest cannot load http://url/login/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. The response had HTTP status code 403. 
app.bundle.js:67773 error Response_body: ProgressEventbubbles: falsecancelBubble: falsecancelable: falsecurrentTarget: XMLHttpRequestonabort: undefinedonerror: undefinedonload: undefinedonloadend: undefinedonloadstart: undefinedonprogress: undefinedonreadystatechange: undefinedontimeout: undefinedreadyState: 0response: ""responseText: ""responseType: ""responseURL: ""responseXML: nullstatus: 0statusText: ""timeout: 0upload: XMLHttpRequestUploadonabort: nullonerror: nullonload: nullonloadend: nullonloadstart: nullonprogress: nullontimeout: null__proto__: XMLHttpRequestUploadconstructor: XMLHttpRequestUpload()arguments: nullcaller: nulllength: 0name: "XMLHttpRequestUpload"prototype: XMLHttpRequestUploadconstructor: XMLHttpRequestUpload()arguments: nullcaller: nulllength: 0name: "XMLHttpRequestUpload"prototype: XMLHttpRequestUpload__proto__: XMLHttpRequestEventTarget()<function scope>onabort: (...)onerror: (...)onload: (...)onloadend: (...)onloadstart: (...)onprogress: (...)ontimeout: (...)Symbol(Symbol.toStringTag): "XMLHttpRequestUpload"__proto__: XMLHttpRequestEventTarget__proto__: XMLHttpRequestEventTarget()<function scope>onabort: (...)onerror: (...)onload: (...)onloadend: (...)onloadstart: (...)onprogress: (...)ontimeout: (...)Symbol(Symbol.toStringTag): "XMLHttpRequestUpload"__proto__: XMLHttpRequestEventTargetwithCredentials: false__proto__: XMLHttpRequestdefaultPrevented: falseeventPhase: 0isTrusted: trueisTrusted: truelengthComputable: falseloaded: 0path: Array[0]returnValue: truesrcElement: XMLHttpRequesttarget: XMLHttpRequesttimeStamp: 2726.8050000000003total: 0type: "error"__proto__: ProgressEventheaders: Headers_headersMap: Mapsize: (...)__proto__: Map<entries>[0]No Entries__proto__: Objectstatus: 200statusText: "Ok"type: 3url: null__proto__: ObjectarrayBuffer:()blob:()constructor: Response(responseOptions)arguments: [Exception: TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context. 
    at Function.remoteFunction (<anonymous>:3:14)]caller: (...)length: 1name: "Response"prototype: Object__proto__:()<function scope>json:()arguments: (...)caller: (...)length: 0name: ""prototype: Object__proto__:()<function scope>text:()__proto__: Object 
+0

Eğer isteğiniz için aldığınız geçerli durum kodu nedir kullanarak sunucu tarafında istemci alanına izin gerekir

https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

vardı? Bu ipucu almak için abone olduğunuzda sadece ikinci bir geri dönüş ... –

+0

Aboneliğinizdeki hata işleyicisini ekleyin. .subscribe ((res) => console.log ("res", res), err => console.log ('error ', err)) '' ne aldığınızı görmek için. –

+0

Merhaba ... güncellenmiş sorumu gördüm – kosala

cevap

1

günlük olan

hata işleme eklendi. Ön kontrol isteğine yanıt, erişim denetimi kontrolünden geçmez: İstenen kaynağa 'Erişim-Kontrol-İzin-Kökeni' başlığı yok. Bu nedenle 'http://localhost:8100' kökeni erişimine izin verilmiyor. Yanıt HTTP durum kodunu 403. Size uygun başlıklarını