PS :我检查过很多帖子,但无法得到满意的解决方案。 (因此,如果您将其标记为重复,那么请分享答案)
我正在使用离子2,它具有非常基本的功能,即向服务器发送post请求。我使用的很简单import { Http } from '@angular/http';
。
代码
var link = 'https://mywebsite.com/myws/Login';
var data = JSON.stringify({ username: this.username, password: this.password });
this.http.post(link, data)
.subscribe(data => {
console.log(data);
}, error => {
console.log("Oooops!");
});
的package.json
{
"name": "medical-bot",
"version": "0.0.0",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "4.1.2",
"@angular/compiler": "4.1.2",
"@angular/compiler-cli": "4.1.2",
"@angular/core": "4.1.2",
"@angular/forms": "4.1.2",
"@angular/http": "4.1.2",
"@angular/platform-browser": "4.1.2",
"@angular/platform-browser-dynamic": "4.1.2",
"@ionic-native/core": "3.10.2",
"@ionic-native/splash-screen": "3.10.2",
"@ionic-native/status-bar": "3.10.2",
"@ionic/storage": "2.0.1",
"ionic-angular": "3.3.0",
"ionicons": "3.0.0",
"rxjs": "5.1.1",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.11"
},
"devDependencies": {
"@ionic/app-scripts": "1.3.7",
"typescript": "2.3.3"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard",
"cordova-plugin-device"
],
"cordovaPlatforms": [],
"description": "MedicalBot: An Ionic project"
}
错误
当我在chrome上运行时出现以下错误
ERROR TypeError: Cannot read property 'getDOM' of undefined
at CookieXSRFStrategy.configureRequest (xhr_backend.js:167)
at XHRBackend.createConnection (xhr_backend.js:207)
at httpRequest (http.js:20)
at Http.request (http.js:120)
at Http.post (http.js:137)
at LoginPage.doLogin (login.ts:37)
at Object.eval [as handleEvent] (LoginPage.html:113)
at handleEvent (core.es5.js:11892)
at callWithDebugContext (core.es5.js:13184)
at Object.debugHandleEvent [as handleEvent] (core.es5.js:12772)