homepage Welcome to WebmasterWorld Guest from 54.205.188.59
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Unbind infinite scroll if 301 response?
jon22




msg:4620255
 8:26 am on Oct 31, 2013 (gmt 0)

I'm implementing infinite scroll into my product listings on my site but I have a problem with finding the last page, the PHP script I'm working with automatically does a 301 redirect after the last page has been reached to a similar page (a filtered version eg best sellers) instead of returning a 404 so the script keeps loading the same items over and over.

I wondered if it's possible to check if the response is 301 before fetching the items then unbind infinite scroll?

<script type="text/javascript">

$(function(){

var $container = $('#catProdContainer');

$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.productlisting-box',
columnWidth: 113,
bufferPx: 0
});
});


// Infinite Scroll
$container.infinitescroll({
navSelector : '.paginationNav', // selector for the paged navigation
nextSelector : '.paginationNav a.button-productlisting-next', // selector for the NEXT link (to page 2)
itemSelector : '.productlisting-box', // selector for all items you'll retrieve
loading: {
finishedMsg: '<div class="thumb-scroll"><i class="icon-thumbs-up"></i></div>',
//img: '/images/ajax-loader.gif',
pixelsFromNavToBottom: 40
},
debug : true
},

// trigger Masonry as a callback
function( newElements ) {
// hide new items while they are loading
var $newElems = $( newElements ).css({ opacity: 0 });
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
// show elems now they're ready
$newElems.animate({ opacity: 1 });
$container.masonry( 'appended', $newElems, true );
});
}


});

});


</script>

 

lucy24




msg:4620275
 10:50 am on Oct 31, 2013 (gmt 0)

###. Was it you that asked an almost identical question in this forum yesterday? Whether it was or wasn't: Moderators are currently working on that parallel thread, so it would probably make sense to hang on until everything gets stabilized or consolidated. The wording was different, but the underlying problem was the same.

jon22




msg:4620286
 11:50 am on Oct 31, 2013 (gmt 0)

Yes that was me, I thought I broke the rules because of a link or something, I didn't think it would still be in moderation...

lucy24




msg:4620405
 8:06 pm on Oct 31, 2013 (gmt 0)

I think you did link to your site, but the problem was laid out clearly enough that the post still makes sense if everything is exemplified. I remember it vividly because I composed a long and careful reply and then got whacked with the glaring yellow "In Moderation" message. (I would suggest that you contact the moderator directly, but it's a name I don't even recognize :()

Short version: a javascript-only solution seems like a bandaid fix for an underlying php problem. The 404 ought to come from the php before the page is ever built.

jon22




msg:4620417
 8:28 pm on Oct 31, 2013 (gmt 0)

How can I contact the moderator? what's their name?

Well it's not really a problem with the php as such because the developer told me it was done for seo, it's an amazon api script so when products go out of stock or are unavailable for some reason the store pages don't just 404 but then again heavy use of 301's can't be good for seo, but that's not my problem :) Actually thinking about it 404's shouldn't harm a site for seo, especially a shopping site it just looks like the site is updated more often surely?

Anyway...It's not open-source, modifying the script is not an option my only choice is a javascript fix, worst case I'll have to use regular pagination which would suck! :( Infinite scroll is one of the main features.

I found this: (statusCode)

$.ajax({

statusCode: {

301: function() {
alert("Alert!");
}
}
});

I just don't know how to implement it or if you can use it with I/S, I need a jquery expert.

Readie




msg:4620529
 9:45 am on Nov 1, 2013 (gmt 0)

The developer you used is very misinformed about SEO. An out of stock product 301'ing? What happens when that product comes back in stock, and all your users browsers, and all the search engines have cached that product as moved permanently?

lucy24




msg:4620533
 10:29 am on Nov 1, 2013 (gmt 0)

when products go out of stock or are unavailable for some reason the store pages don't just 404 but then again heavy use of 301's can't be good for seo, but that's not my problem

Isn't it? It's your site, right?

Do you have many products that routinely go in and out of stock for long periods of time? If so, find a cohesive way to deal with them. Think of the desired human interaction first, and then code to match. Not the other way around!

Temporarily out of stock > flag on same page "We'll get more next week" or similar
Replaced/updated item > redirect, possibly with pause to say "We don't have those any more, but these are even better"
Discontinued item > custom page with targeted information for humans
Seasonal item > variant page "We have these every July"

Is your scroll intended to show only the products you have in stock right now? Or everything you sell in the course of a year? Or something in between?

Or, in different terms: Should each displayed item correspond to a page that currently exists?

There are only so many kinds of responses a php script can send out: 302, 301, 410 and that's about it. (I deliberately left out 404; save those for things you never carried and never will.) But that doesn't mean that every unfilled request has to be shoehorned into one of three options. You don't want to annoy customers by showing off a product that won't be back until next March. But you also don't want to act as if a product doesn't exist, when it's only gone for a day or two.

None of which really answers your question, but never mind.

jon22




msg:4620559
 12:24 pm on Nov 1, 2013 (gmt 0)

The developer you used is very misinformed about SEO. An out of stock product 301'ing? What happens when that product comes back in stock, and all your users browsers, and all the search engines have cached that product as moved permanently?


I'm not exactly sure to be honest, as I say that side of it isn't my responsibility, it's just the way the pagination has been coded.

Isn't it? It's your site, right?


No, I'm just coding a template for the script.

You both raise some good points which I'm going to mention to the developer.

Do you have many products that routinely go in and out of stock for long periods of time?


The api updates every hour due to Amazons TOS so I would think so.

Think of the desired human interaction first, and then code to match. Not the other way around!


This is exactly my way of thinking.

Is your scroll intended to show only the products you have in stock right now? Or everything you sell in the course of a year? Or something in between?


It's designed to replace the pagination and load the products on the same page, as you scroll to the bottom the itemSelector (each product) from page two are loaded, then 3 then 4, hence my problem with the last page when it hits a 301 instead of a 404 - the script doesn't know it's reached the end.

If it's okay I'll post a link to my test site and the page in question, open firebug console and keep scrolling you'll see what's going on - the last page is supposed to be page 4.

prospera.freshstoretemplates[dot]com/surf/

lucy24




msg:4620662
 9:05 pm on Nov 1, 2013 (gmt 0)

If it's okay I'll post a link to my test site

It almost certainly isn't OK, so better not.

Can't you set up the php to loop back to the beginning of the list when it reaches the end? I know this is trivial, because I only speak three words of php-- and that's one of them. And then whatever values the php ends up with will be passed along to the javascript/ajax.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved