javascript - Read a text file with PHP and return it to JavaScript
问题描述
I want to get the content of a txt file in JavaScript, so I want to call a php file to open and save the content of the text file into a variable and return it to JS is that possible?
I've sent variables from js to php with $.post()
and I tried to use $.get("php file")
but I can't return the file content can anybody help me?
解决方案
要从服务器读取/获取文件并在 javascript/jquery 中使用它的内容,您可以使用速记方法$.get
。在回调函数内部,您可以处理从服务器返回的数据。
$.get("file.php", function(data) {
console.log(data);
});
推荐阅读
- sql - SQL查询仅获取值等于当前日期的列
- python - 如果字符串中包含停用词,则从字符串中删除一个元素
- google-app-maker - 如何防止appmaker中的重复记录?
- c# - 使用 UTF8 编码创建数据库
- amazon-web-services - 无法访问 tmp 目录中的文件
- python - MySQL 5.6 中的全局查询超时
- kotlin - Kotlin 与 Objective-C 框架的多平台/原生互操作性
- c# - 我如何从一开始就为场景中的每个按钮调用相同的函数?
- javascript - zk zAu.send 函数 - org.zkoss.zk.ui.event.MouseEvent 不能转换为 org.zkoss.zk.ui.event.ForwardEvent
- laravel - 如何修复类 Illuminate\Database\Eloquent\Collection 的对象无法转换为 int