简体   繁体   English

外部php文件的500(内部服务器错误)

[英]500 (Internal Server Error) of external php file

I am currently using WP Web Scraper version 3.2. 我目前正在使用WP Web Scraper 3.2版。 Once I insert the shortcode or template tag (php code) directly into my page, the plugin works perfectly fine and the values appear. 一旦我将短代码或模板标签(php代码)直接插入到我的页面中,插件就可以正常运行并显示值。 I decided to place the template tag in an external php file and use Ajax to call the code after a specific amount of time, and once I do so nothing appears and my console shows 500 (Internal Server Error). 我决定将模板标签放在外部php文件中,并在特定时间后使用Ajax调用代码,一旦我这样做,就不会出现任何内容,我的控制台显示500(内部服务器错误)。 I get a message which says "Failed to load resource". 我收到一条消息“无法加载资源”。 My php file (test.php) contains this (assuming that URL is the actual link to the website): 我的php文件(test.php)包含这个(假设URL是网站的实际链接):

<?php
echo wpws_get_content('URL', 'body > table > tbody > tr:nth-child(1) > td:nth-child(8)' );

On my page, I use Javascript to load this file and it looks like this: 在我的页面上,我使用Javascript加载此文件,它看起来像这样:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready( function() {
setInterval(function () {
    $('#demo').fadeOut('slow', function() {
        $('#demo').load('http://localhost:8888/test-site/wp-content/my-php-files/test.php', function() {
            $('#demo').fadeIn('slow');
        });
    });
}, 6000);
});
</script>

<div id="demo"></div>

I tested the PHP file with other codes to check if they work and they work perfectly fine. 我用其他代码测试了PHP文件以检查它们是否有效并且它们工作得非常好。 One example of php I inserted in that file was: 我在该文件中插入的一个例子是:

<?php
echo(rand(10,100));

In this last example, using my script, a random number is loaded from the external file every 6 seconds without having to refresh the page and I get no errors. 在最后一个示例中,使用我的脚本,每6秒从外部文件加载一个随机数,而不必刷新页面,我没有错误。 I deduced from this the template tag provided by the plugin is causing the problem. 我从中推断出插件提供的模板标签导致了问题。 How can I load this template tag into my script? 如何将此模板标记加载到我的脚本中? Any suggestions? 有什么建议么?

King regards!! 王尊敬!!

对我来说最简单的方法是通过在顶部插入这行代码将WordPress环境加载到php文件中:

require('../../wp-blog-header.php');

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

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