简体   繁体   English

Ajax-可加载的PHP脚本

[英]Ajax - loadable php-script

I'm dynamically loading different content from db, using ajax. 我正在使用ajax从数据库动态加载不同的内容。

So, when I'm loading plain text - it shows correctly, but when there is a php-script in content, it wouldn't be interpreted by php-server, so I can see a code at the page. 因此,当我加载纯文本时-可以正确显示,但是当内容中包含php-script时,php-server不会解释它,因此我可以在页面上看到代码。 Could I load php script like this way? 我可以像这样加载php脚本吗?

You have a server setting issue. 您有服务器设置问题。 whether you Ajax a file or pull it in directly in the browser, the server sees the request the same way. 无论您是Ajax文件还是直接在浏览器中将其拉入,服务器都会以相同的方式看到请求。 You need to tell your web sever to parse php files not serve them. 您需要告诉您的网络服务器以解析不为它们提供服务的php文件。

This is web-server misconfiguration. 这是Web服务器配置错误。 You should look at php installation instruction . 您应该查看php 安装说明 If you are using Apache2 server, then you should add following line in your httpd.conf : 如果您使用的是Apache2服务器,则应在httpd.conf添加以下行:

AddHandler application/x-httpd-php .php

Make sure that you have mod_php5 loaded. 确保您已加载mod_php5

I'm dynamically loading different content from db, using ajax 我正在使用ajax从数据库动态加载不同的内容

You can't directly query the database using javascript, you are probably posting to some server side script which in turn talks to the database and returns the result in some form (XML, JSON, plain text). 您无法使用javascript直接查询数据库,您可能正在发布到某些服务器端脚本,这些脚本又与数据库进行对话并以某种形式(XML,JSON,纯文本)返回结果。 If I understand correctly from your description you have a php-script stored in the database which you want to execute on the server and return the result of this execution to the client. 如果我从您的描述中正确理解,则您有一个php脚本存储在数据库中,您希望在服务器上执行该脚本并将该执行的结果返回给客户端。 One way you could achieve this is to have a php-script which queries the database, eval s the content and returns the result as plain text. 实现此目的的一种方法是使用php脚本查询数据库, 评估内容并将结果以纯文本形式返回。

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

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