简体   繁体   English

使用 (PHP) 从 Mysql 获取数据并使用 JSON 将其发送到 typescript/javascript

[英]Get Data from Mysql using (PHP) and send it to typescript/javascript using JSON

I have got data from mysql in php, and i want to send it to typescript using JSON.我在 php 中从 mysql 获得了数据,我想使用 JSON 将其发送到打字稿。 but when load the php page.但是当加载 php 页面时。 nothing showed in the screen.屏幕上没有显示任何内容。 It always shows a blank page.它总是显示一个空白页。

$select  ="SELECT * from `filiere`";
$run = mysqli_query($connect, $select);
$temp = array();

while($row=mysqli_fetch_row($run)) {
    $temp[] = $row;
}
echo json_encode($temp);

from the code, it should show the data in json format.从代码中,它应该以json格式显示数据。

what it is the problem?这是什么问题?

In PHP, an unexpeted blank page usually means some kind of error + error reporting turned off.在 PHP 中,意外的空白页面通常意味着某种错误 + 错误报告已关闭。

Try to turn error reporting on尝试打开错误报告

ini_set('display_startup_errors',1); 
ini_set('display_errors',1);
error_reporting(E_ALL);

EDIT #1: Based on the comments, it seems that json_encode() fails, so returns false (echoing false will result in a blank page).编辑 #1:根据评论,似乎json_encode()失败,因此返回false (回显false将导致空白页面)。

The json_last_error() and/or json_last_error_msg() functions should be used to find the error.应该使用json_last_error()和/或json_last_error_msg()函数来查找错误。

EDIT #2: The first argument of json_encode() must hold only UTF-8 encoded strings.编辑 #2: json_encode()的第一个参数必须只包含 UTF-8 编码的字符串。

I think i've understood where is my error.我想我已经明白我的错误在哪里。 You are all right.你没事。 i have some data with frensh letters like ('é', 'ù'..).我有一些带有法语字母的数据,例如 ('é', 'ù'..)。 I think that was the problem.我认为这就是问题所在。

Thank you all谢谢你们

您是否在 php 上设置了端点内容类型?

header('Content-Type: application/json');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM