Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Reloading A php script with jquery

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #26843

    Hi,
    I have been trying to reload a widget that is displaying a twitter updates every couple of seconds, I have found this jquery script to do that.


    var auto_refresh = setInterval(
    function()
    {
    $('.twitter-hash-tag-widget').fadeOut('slow').load(' script to be loaded ').fadeIn("fast");
    }, 20000);

    The problem is that when i put the full php script url it says error 500 server error every time it reloads (using firbug console) I was just wondering because its a widget it may be trying to reload everything in that php script and not just the function that controls the twitter updates. Im not very good at php yet and if someone could figure out what I have to do to get this working, I would appreciate it. Here is the widget source…


    /*
    Plugin Name: Twitter Hash Tag Widget
    Plugin URI: http://webdevstudios.com/support/wordpress-plugins/
    Description: A widget for displaying the most recent twitter status updates for a particular hash tag.
    Author: Brad Williams
    Author URI: http://webdevstudios.com/
    Version: 1.1

    Copyright (c) 2009-2010 Brad Williams (http://webdevstudios.com/)
    Twitter Hash Tag Widget is released under the GNU General Public License (GPL)
    http://www.gnu.org/licenses/gpl-2.0.txt
    */

    class WP_Widget_Twitter_Hash_Tag extends WP_Widget {

    function WP_Widget_Twitter_Hash_Tag() {
    $widget_ops = array('description' => __( 'Real time Twitter hash tag following' ) );
    $this->WP_Widget('twitter_hash_tag', __( 'Twitter Hash Tag' ), $widget_ops);
    }

    function widget( $args, $instance ) {
    extract($args, EXTR_SKIP);

    $api_url = 'http://search.twitter.com/search.json';

    $title = ! empty($instance) ? esc_attr($instance) : false;
    $hashtag = ! empty($instance) ? ltrim(esc_attr($instance), '#@') : 'wordpress';
    $number = ! empty($instance) ? $instance : 3;
    $images = $instance;

    echo $before_widget;
    if ( $title )
    echo $before_title . "$title" . $after_title;

    $raw_response = wp_remote_get("$api_url?q=%23$hashtag&rpp=$number");

    if ( is_wp_error($raw_response) ) {
    $output = "

    Failed to update from Twitter!

    n";
    $output .= "n";
    $output .= get_option('twitter_hash_tag_cache');
    } else {
    if ( function_exists('json_decode') ) {
    $response = get_object_vars(json_decode($raw_response));
    for ( $i=0; $i < count($response); $i++ ) {
    $response[$i] = get_object_vars($response[$i]);
    }
    } else {
    include(ABSPATH . WPINC . '/js/tinymce/plugins/spellchecker/classes/utils/JSON.php');
    $json = new Moxiecode_JSON();
    $response = @$json->decode($raw_response);
    }

    $output = "n";
    }

    if ( ! is_wp_error($raw_response) )
    update_option('twitter_hash_tag_cache', $output);

    echo $output;

    echo $after_widget;
    }

    function update( $new_instance, $old_instance ) {
    $new_instance = (array) $new_instance;
    $instance = ! empty($new_instance) ? esc_attr($new_instance) : '';
    $instance = ! empty($new_instance) ? ltrim(esc_attr($new_instance), '#@') : 'wordpress';
    $instance = ! empty($new_instance) ? $new_instance : 3;
    $instance = ! empty($new_instance) ? true : false;
    return $instance;
    }

    function form( $instance ) {
    $title = ! empty($instance) ? esc_attr($instance) : '';
    $hashtag = ! empty($instance) ? ltrim(esc_attr($instance), '#@') : 'wordpress';
    $number = ! empty($instance) ? $instance : 3;
    $images = ! empty($instance) ? $instance : true;

    ?>







    Do not include the #









    }

    }

    function wp_widget_twitter_hash_tag_init() {
    add_option('twitter_hash_tag_cache', '');
    }

    add_action('widgets_init', create_function('', 'return register_widget("WP_Widget_Twitter_Hash_Tag");'));

    register_activation_hook(__FILE__, 'wp_widget_twitter_hash_tag_init');

    ?>

    I know this is probably a lot to ask, but any help is appreciated.

    #76114
    Rob MacKay
    Participant

    If I was going to do this I would create a PHP function that echo’s the responce in JSON – then use the wonderful ajax function to pull the JSON responce from the function.

    http://api.jquery.com/jQuery.ajax/

    I think load would work, but I find ajax just as easy and a little better laid out in my mind…

    Sorry if that didn’t help too much but I don’t have time right now to go through your post fully lol :)

    #76119
    hardik
    Member

    well looking at script its too difficult to understand what could be cause of error.
    but for 500 error’s.

    there are things like either if you server is older
    or if you use some function which is blocking something or
    doing something with allowed resources or its not allowed in
    server.

    but isssue should be in code.

    i don’t know if it helps or not but please check this three plugins

    http://www.webresourcesdepot.com/3-jquery-twitter-plugins-adding-tweets-to-your-website/

    which might help the serve your purpose

    #76130
    darren
    Member

    So you think it might be the plugin that is causing the error? Should I call the script just like I was before?

    #76131
    darren
    Member

    Sorry I guess the first one was ajax anyway, thanks for the link!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.