【问题标题】:JQUERY PHP on Chrome giving a 500 error for GET RequestChrome 上的 JQUERY PHP 为 GET 请求提供 500 错误
【发布时间】:2016-02-18 05:59:29
【问题描述】:


PHP 代码在这里并利用Twitter API Exchange PHP File

<?php

    require_once('TwitterAPIExchange.php');        

    $settings = array(
    'oauth_access_token'            => 'whatever',
    'oauth_access_token_secret'     => 'whatever',
    'consumer_key'                  => 'whatever',
    'consumer_secret'               => 'whatever'
    );


    $query = "%23georgeezra";
    $url = "https://api.twitter.com/1.1/search/tweets.json";
    $requestMethod = "GET";
    $getfield = '?q='.$query.'&count=5';
    $twitter = new TwitterAPIExchange($settings);
    $result = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
    echo $result;

?>

我已在 Twitter 上的开发工具上运行此查询,查询按要求执行,但在 Chrome 和 Firefox 上,在 Apache2 服务器上运行并使用 JQuery 2.1.1 版时会出现 500(内部服务器错误)错误


jQuery 代码:

$(function(){

    $.ajax({
        url: 'ezra.php',
        type: 'GET',
        success: function(response) {

            if (typeof response.errors === 'undefined' || response.errors.length < 1) {

                var $tweets = $('<ul></ul>');
                $.each(response, function(i, obj) {
                    $tweets.append('<li>' + obj.text + '</li>');
                });

                $('.tweets-container').html($tweets);

            } else {
                $('.tweets-container p:first').text('Response error');
            }
        },
        error: function(errors) {
            $('.tweets-container p:first').text('Request error');
        }
    });
});

【问题讨论】:

  • 打开 PHP 错误报告,或检查您的 apache 日志
  • 是原代码中-&gt;buildOauth之间的空格还是复制错误?

标签: javascript php jquery html twitter


【解决方案1】:
$result = json_decode(...)

应该调用json_encode,而不是json_decode。而$assoc = TRUE 不是json_encode 的合适第二个参数。

您还需要添加:

dataType: "json"

拨打$.ajax 电话。

【讨论】:

  • 感谢我删除了 $assoc 并将其更改为 json_encode 但它仍然无法正常工作。
  • PHP 致命错误:require_once():无法在 /var/www 中打开所需的 'twitter_proxy.php' (include_path='.:/usr/share/php:/usr/share/pear') /html/Web Project/ezra.php 在第 3 行,引用者:localhost/Web%20Project/artist1.html 但是没有意义,因为 artist1.html 没有这样的行
  • 也没有twitter_proxy.php
  • 该行在ezra.php,而不是artist1.html
  • 这就是错误消息所抱怨的——没有twitter_proxy.php,但ezra.php 需要它。
【解决方案2】:

原来 TwitterAPIExchange.php 文件需要 cURL 才能工作。
我跑了:sudo apt-get install php5-curl,然后是sudo /etc/init.d/apache2 restart,就这样。

【讨论】:

    猜你喜欢
    • 2021-04-23
    • 1970-01-01
    • 2023-01-02
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 2016-08-21
    • 1970-01-01
    相关资源
    最近更新 更多