Jump to content


These Forums Are Now Read-Only


For TubePress support, please post a question here or open a support ticket and we will be glad to assist.


Photo

ajax 404 error with correct response


  • Please log in to reply
4 replies to this topic

#1 Chris Cowell

Chris Cowell

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 04 September 2011 - 09:23 PM

Hi Eric,

I am writing a plugin using WP3.2 and I am trying to import a gallery using an ajax call. I am able to get the correct html response along with a 404 header. I tried hardcoding the header but that does not seem to work. I hope your fresh eyes will see the problem. Here's the ajax and php code:

$j('#mybutton').click(
        function() {
                dataString = $j("#my-ajax-form").serialize();
                $j.post("/wp-content/plugins/myplugin/getref.php",
                        dataString,
                        function(data){
                                $j("#first-tab").html(data).hide().fadeIn(1000);
                        }
                );
                $j("#second-tab").empty();
                for( i=1; i < 5; i++){
                        $j.ajax({
                                type: 'POST',
                                url: "/wp-content/plugins/myplugin/getcommentary.php",
                                data: dataString,
                                success: function(data){
                                                $j("#second-tab").append(data);
                                         } 
                        });
                }
               $j("#third-tab").empty();
                $j.ajax({
                        type: 'POST',
                        url: "/wp-content/plugins/myplugin/getvideos.php",
                        data: dataString,
                        success: function(data){
                                        $j("#third-tab").append(data);
                                }, 
                        error:  function(data){ 
                                        //$j("#third-tab").append(data.responseText);
                                        alert(data.responseText);
                                },
                });
               $j("#fourth-tab").empty();
                for( i=1; i < 2; i++){
                        $j.ajax({
                                type: 'POST',
                                url: "/wp-content/plugins/myplugin/gethistory.php",
                                data: dataString,
                                success: function(data){
                                               $j("#fourth-tab").append(data);
                                         }
                        });
                }
                return false;
        }
);

<span class="syntaxdefault"><php?require_once('/home/website/public_html/wp-content/plugins/tubepress_pro_2_2_0/sys/classes/TubePressPro.class.php');require_once('../../../wp-load.php');header('Response: HTTP/1.1 200 OK');  // Trying to override the 404 header$searchterms .= "motorcycles";print TubePressPro::getHtmlForShortcode("resultsPerPage='3' mode='tag' tagValue='" . $searchterms . "'");?></span>

Thanks for you help,

Chris

#2 eric

eric

    Lead Developer

  • TubePress Staff
  • 2787 posts

Posted 06 September 2011 - 07:34 PM

Hi Chris,

This is a known, and IMHO terrible, problem when using Ajax in a WordPress environment (but outside of WordPress's Ajax framework). Basically, WordPress will set the 404 header no matter how hard you try to stop it. I spent hours on this!

The workaround I use is to use "complete" instead of "success" in your jQuery.ajax() calls. See this code for examples of how I got jQuery to ignore the 404 on jQuery.get() and jQuery.load().

Your mileage may vary, especially since you have a separate callback set up for error handling. jQuery.complete() is passed a jqXHR instance, though, so you could likely just examine that and invoke your existing "success" and "error" callbacks based on the status.

#3 Chris Cowell

Chris Cowell

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 07 September 2011 - 12:57 PM

Thanks Eric,

After trying your solution, which I believe should work, the code does not execute in my tabbed window. I am now using Tubepress 2.2.7 which I activated. I double-checked that stylesheets and tubepress.js were included. My test environment uses https. Tubepress works fine under that condition when I created a sample page. I am still working on a plugin that will dynamically generate youtube and vimeo videos. I continue to get a 404, but the "complete" script executes. Here's my latest test code where I hardcode the responseText. It appears some of the div classes are unreachable?

$j("#third-tab").empty();
                $j.ajax({
                        type: 'POST',
                        url: "/wp-content/plugins/moto_plugin/getvideos.php",
                        data: dataString,
                        complete: function(data){
                                        $j("#third-tab").html(data.responseText).hide().fadeIn(1000);
                                  },
                });

<?phprequire_once('../../../wp-load.php');require_once('/home/motorcycle/public_html/wp-content/plugins/tubepress_pro_2_2_7/sys/classes/TubePressPro.class.php');//header('Response: HTTP/1.1 200 OK');if (array_key_exists('q', $_POST) ) {        $searchterms    = trim($_POST['q']);}else {        $args           = parseArgs( $argv );        $searchterms    = getArg( $args, 'terms' );}//print TubePressPro::getHtmlForShortcode("resultsPerPage='3' mode='tag' tagValue='" . $searchterms . "'");//$videos = TubePressPro::getHtmlForShortcode("resultsPerPage='3' mode='tag' tagValue='motorcycles'");$videos = <div class="tubepress_container" id="tubepress_gallery_1085457538">  <div class="tubepress_normal_embedded_wrapper" style="width: 425px">    <div id="tubepress_embedded_title_1085457538" class="tubepress_embedded_title">      Classic Game Room HD - MARIO KART Wii review Part 1        </div>    <div id="tubepress_embedded_object_1085457538">      <iframe class="youtube-player" type="text/html" width="425" height="350" src="http://www.youtube.com/embed/Ae4hCqZWoqg?rel=1&autoplay=0&loop=0&fs=1&showinfo=0&wmode=transparent" frameborder="0"></iframe>    </div>  </div>  <div id="tubepress_gallery_1085457538_thumbnail_area" class="tubepress_thumbnail_area">    <div class="pagination"><span class="current">1</span><a rel="nofollow" href="https://motorcycles.com:443/wp-content/plugins/moto_plugin/getvideos.php?tubepress_page=2">2</a><a rel="nofollow" href="https://motorcycles.com:443/wp-content/plugins/moto_plugin/getvideos.php?tubepress_page=3">3</a><a rel="nofollow" href="https://motorcycles.com:443/wp-content/plugins/moto_plugin/getvideos.php?tubepress_page=4">4</a><a rel="nofollow" href="https://motorcycles.com:443/wp-content/plugins/moto_plugin/getvideos.php?tubepress_page=5">5</a><span class="tubepress_pagination_dots">...</span> <a rel="nofollow" href="https://motorcycles.com:443/wp-content/plugins/moto_plugin/getvideos.php?tubepress_page=99">99</a><a rel="nofollow" href="https://motorcycles.com:443/wp-content/plugins/moto_plugin/getvideos.php?tubepress_page=100">100</a><a rel="nofollow" href="https://motorcycles.com:443/wp-content/plugins/moto_plugin/getvideos.php?tubepress_page=2">next »</a></div>    <div class="tubepress_thumbs">      <div class="tubepress_thumb">        <a id="tubepress_image_Ae4hCqZWoqg_1085457538" rel="tubepress_youtube_normal_1085457538">           <img alt="Classic Game Room HD - MARIO KART Wii review Part 1" src="http://i.ytimg.com/vi/Ae4hCqZWoqg/1.jpg" width="120" height="90" />        </a>        <dl class="tubepress_meta_group">          <dt class="tubepress_meta tubepress_meta_title">Title</dt><dd class="tubepress_meta tubepress_meta_title"><a id="tubepress_title_Ae4hCqZWoqg_1085457538" rel="tubepress_youtube_normal_1085457538">Classic Game Room HD - MARIO KART Wii review Part 1</a></dd>          <dt class="tubepress_meta tubepress_meta_runtime">Runtime</dt><dd class="tubepress_meta tubepress_meta_runtime">7:14</dd>

Thanks for you help.
Chris

#4 eric

eric

    Lead Developer

  • TubePress Staff
  • 2787 posts

Posted 10 September 2011 - 05:48 PM

Hi Chris,

That code looks correct to me - not sure why it wouldn't populate the "#third-tab" div. Even if the div is hidden, it should still fill in the HTML. If you use Firebug and put in a breakpoint in complete(), does the "data" variable hold anything?

Feel free to PM me your site if you'd like me to take a look first-hand. I'll do my best!

#5 Chris Cowell

Chris Cowell

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 13 October 2011 - 02:38 PM

Hi Eric,

I am back to working on this ajax issue. I downloaded the latest 2.2.9 Pro and found the same issue. I am PMing a link to my test area. Thanks for any help possible.

Chris