将 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这个标签就可以显示了。
感谢楼上的各位

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
