android - 在 Ionic 4 中进行 AJX 调用时遇到问题
问题描述
我正在制作一个应用程序,它将使用 AJAX 请求获取 MySQL 数据并将一些数据发布到数据库中。这是一个问题,它没有在我的项目中进行 AJAX 调用
我正在使用 Ionic 4 和 PHP-MySQL 作为后端服务
import { Component, OnInit } from '@angular/core';
import * as $ from 'jquery';
import { data } from 'jquery';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
public press() {
// tslint:disable-next-line:only-arrow-functions
$.ajax({
url: "demo_test.txt", // or any URL
success: function(result) {
$("#div1").html(result);
}});
}
}
我想在我的 Ionic 4 应用程序中从远程 HTML、PHP 或文本文件进行 AJAX 调用。
解决方案
您应该使用 angular/http 中的 httpclient。这是非常直接的事情。
this.http.get(url).subscribe(data => {
console.log(data)
}, err => {
console.log(err)
}
推荐阅读
- sqlite - 如何打开 db.sqlite3 文件并查看其内容?
- c++ - 如何将stl容器保存在磁盘中?
- javascript - 如何将 href 按钮添加到 elseif 语句
- python-3.x - 基于逗号拆分并在 Python 中创建新数据框
- flutter - 从有状态小部件更新无状态小部件
- prestashop - Prestashop 结账时的价格编辑
- python-3.x - 如何等到客户端消息以 \r\n\r\n 或 \n\n 结束,然后发回响应
- r - 如何使用 dplyr 按组计算比例?
- .net - IIS SOAP Web 服务 - 客户端未收到响应
- php - Symfony - 创建“表格”表单