dongrong7267 2015-02-16 23:18
浏览 21
已采纳

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

I am currently using WP Web Scraper version 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. 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). 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
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:

<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. 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. 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!!

  • 写回答

1条回答 默认 最新

  • dousi1097 2015-02-20 13:32
    关注

    The easiest way for me was loading the WordPress environment into the php file by inserting this line of code at the top:

    require('../../wp-blog-header.php');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据