search
HomeBackend DevelopmentPHP Tutorial将 file_get_content() 返回的内容在 bootStrap 的模态框中显示

php 小白,想实现将 file_get_content() 读到的文本内容,显示在 bootstrap 的 模态框中,不懂怎么实现。

先说下,发帖前已经自己google百度了,没解决。最后聚焦在,如何点击  这个按钮以后,将这个参数 $p(其中$p = ../web/test.php) 传给 file_get_contment()后,再由 file_get_content() 返回的内容传给 模态框里面显示 。

点击这里的按钮,然后在模态框中查看




新人,知道代码有许多不规范,勿喷


回复讨论(解决方案)

请使用ajax:因为.php文件在Apache或者nginx进行解释的时候,会把里面的进行解释,然后翻译成一个html文件,输送到浏览器,用户在客户端点击button去触发file_get_contents是不可能的,除非你之前已经把file_get_contents的内容获取到了并且隐藏(display:none;),然后点击button再display:block;或者点击button的时候,发送ajax请求去获取file_get_contents的内容展示,当然刷新页面也可以。

请使用ajax:因为.php文件在Apache或者nginx进行解释的时候,会把里面的进行解释,然后翻译成一个html文件,输送到浏览器,用户在客户端点击button去触发file_get_contents是不可能的,除非你之前已经把file_get_contents的内容获取到了并且隐藏(display:none;),然后点击button再display:block;或者点击button的时候,发送ajax请求去获取file_get_contents的内容展示,当然刷新页面也可以。



在发帖前,试过ajax,把$p = "../web/index.php" 这个带路径文件名,传到后台后,用file_get_content()得到的内容,是否用 Json格式返回,之前试用,用json格式返回,没成功。所以问题在两点 ; 

在后台中 返回  
echo json_decode(file_get_content($p));


前台,ajax 设置dataType:'json'

也试过,没成

以上,感谢你的回答

这与 file_get_content() 没有直接的关系

1、既然页面使用的是 bootStrap,那么他就是用 ajax 与 服务端 交换信息的
你可将他发出去的内容直接返回,从而判定 bootStrap 中是否正常

2、判定 file_get_content() 结果是否正常
echo file_get_content(提交的路径)
只需在 php 中模拟实现就可以,与客户端无关

3、只在上两个检查都正确无误时,还需要检查数据格式是否正确

file_get_contents只是获取数据,但最后是需要js把获取的数据放入bootstrap。所以与file_get_contents无关。
应该看看返回的内容。

file_get_contents只是获取数据,但最后是需要js把获取的数据放入bootstrap。所以与file_get_contents无关。
应该看看返回的内容。



碰到个奇怪的小问题,ajax返回数据后,alert能显示出来,要是放在input标签里面,也有值,但是放在 div标签里面就不行了,不复杂,就几行代码,但是不懂为什么 div 的就不能显示内容

这是后台的


这是javascipt的函数


这是模态框里面的写法


这是运行结果




想知道,为什么 div 不能显示 ajax返回的内容

file_get_contents只是获取数据,但最后是需要js把获取的数据放入bootstrap。所以与file_get_contents无关。
应该看看返回的内容。



这与 file_get_content() 没有直接的关系

1、既然页面使用的是 bootStrap,那么他就是用 ajax 与 服务端 交换信息的
你可将他发出去的内容直接返回,从而判定 bootStrap 中是否正常

2、判定 file_get_content() 结果是否正常
echo file_get_content(提交的路径)
只需在 php 中模拟实现就可以,与客户端无关

3、只在上两个检查都正确无误时,还需要检查数据格式是否正确




看下5楼的一个小问题,ajax返回的数据不能显示,非常感谢

请使用ajax:因为.php文件在Apache或者nginx进行解释的时候,会把里面的进行解释,然后翻译成一个html文件,输送到浏览器,用户在客户端点击button去触发file_get_contents是不可能的,除非你之前已经把file_get_contents的内容获取到了并且隐藏(display:none;),然后点击button再display:block;或者点击button的时候,发送ajax请求去获取file_get_contents的内容展示,当然刷新页面也可以。



在继续进行的过程中,碰到一个小问题,在5楼,帮看下,非常感谢

因为从后台返回过来的是json数据啊,你用了$.ajax,而且指定了数据类型为json,当然会被解析为json对象。没错,是json对象,而不是字符串。
所以你要么改变指定的数据类型dataType:text或者dataType:html
要么把数据变为json字符串

JSON.stringify(msg)

你获取到的数据是 php 代码,用文本方式才能显示
否则浏览器会把 

php代码要放入 中,否则作为html代码是不会解析的。

做个总结,在后台返回数据,是json格式,在模态框里面,用 textarea这个标签就可以显示了。

感谢楼上的各位

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.