Plugin

Developer
Supported

AJAX Pagination

ExpressionEngine 1.x, ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Laisvunas

     

You must be logged in to post.

AJAX Pagination Not Working - Giving Java pop up AND returning 403 error

Support Request

andrewcretin
andrewcretin

So I have implemented AJAX Pagination to my site however I am not getting the desired results.

This is the snippet of code on my index page to include the embed

<div class="well">
 <
h3>Recently Paid IOU's</h3>

  {embed="embeds/recent_ious" member_id="<?php echo $member_id ?>"}

</div> 

This is the embed file which is located in system/expressionengine/templates/default_site/embeds.group/recent_ious.html

{exp:ajax_pagination:wrapper 
ajax_container
="ajax_container" 
embed_template_url="{homepage}/embeds/recent_ious/" 
xid_element_id="infinite_scroll_xid"
process_indicator="process_indicator" 
process_indicator_scroll="yes" 
parse="inward"
}

{ajax_pagination_container_top}
<div id="ajax_container">
{/ajax_pagination_container_top}

<input type="hidden" id="infinite_scroll_xid" value="{XID_HASH}">
<
input type="hidden" name="csrf_token" value="{csrf_token}">

<
div class="process_indicator">
Loading…
</div>

{exp:query limit="5" sql=
"SELECT field_id_4, member_id, username, screen_name, SUM(`field_id_9`) `total`
FROM 
(SELECT * FROM 
(SELECT field_id_4, field_id_9 
FROM exp_channel_data 
WHERE field_id_5='1' 
AND field_id_13='1'
UNION ALL 
SELECT field_id_5, field_id_9 
FROM exp_channel_data 
WHERE field_id_4='1'
AND field_id_13='1') AS A 
JOIN (SELECT * FROM exp_members) AS B 
ON A.field_id_4=B.member_id ) AS C
GROUP BY member_id
ORDER BY screen_name ASC"
}


   
   {exp
:member:custom_profile_data member_id='{field_id_4}' dynamic="no" style="display:inline;"}
   
   
<p>
   
{if {total} 0}
   I paid {screen_name}  
   ${total}
   {
/if}

   
   {if {total} 
0}
   {screen_name} paid me  
   ${exp
:math formula="{total}*-1" decimals="2"}
   {
/if}

   
   {if {total} 
== 0}
   I owed {screen_name} the same amount he
/she owed meThe debt was cleared!</p>
   
{/if}
   
</p>


   
{/exp:member:custom_profile_data}


        {paginate}
        {exp
:ajax_pagination:links}
         
<ul class="pager" style="display:block;">
         
{if previous_page}
     
<li class="previous pull-left" style="display:inline-block;"><a href="{auto_path}">&larrOlder</a></li>
     <
p style="display:inline-block;">Page {current_page} of {total_pages} pages </p>
     <
li class="next disabled pull-right" style="display:inline-block;"><a href="{auto_path}">Newer &rarr;</a></li>
   
{/if}
   {if next_page}
     
<li class="previous disabled pull-left" style="display:inline-block;"><a href="{auto_path}">&larrOlder</a></li>
      <
p style="display:inline-block;">Page {current_page} of {total_pages} pages </p>
     <
li class="next pull-right" style="display:inline-block;"><a href="{auto_path}">Newer &rarr;</a></li>
   
{/if}
   
</ul>
  
{/exp:ajax_pagination:links}
        {
/paginate}




{
/exp:query}

{ajax_pagination_container_bottom}
</div>
{/ajax_pagination_container_bottom}

{
/exp:ajax_pagination:wrapper} 

I have read that EE won’t allow access to system, therefor access to templates, via the URL.

However when i go directly to http://localhost:8888/index.php/embeds/recent_ious in the URL it returns what would be the first page of results. Then if i go to http://localhost:8888/index.php/embeds/recent_ious/P5 in the URL it returns what would be the second page of results.

In chrome I am running console and the error i receive when I click the ‘next page’ button looks like this

POST http://localhost:8888/index.php/embeds/recent_ious/P5 403 (Forbidden)
ajaxPagination1.fetch
Data onclick

The problem here is that the POST function isn’t able to grab the contents from the recent_ious embedded file.

Attached are images of the site and the popup i receive when i try to go to the next page of posts. 

ANY help would be much appreciated. I can attach files as needed too.

Laisvunas
# 1
Developer
Laisvunas

Hi,

It’s complicated to develop a website using AJAX on localhost. Can you put the code on a remote server?

andrewcretin
# 2
andrewcretin

Hey,

Thanks for the reply. I got it figured out. Expression engine doesn’t allow POST requests through the URL so what I had to do was use a GET a request rather.  It was as simple as changing POST to GET on a line of code in the php file that is associated with the plug in!

bigsouth
# 3
bigsouth

I’m having the exact same problem with a pop up. Tho changing POST to GET didn’t help me at all :-/
Is there a workaround @Laisvunas? Or do you know a solution?

I can post my code, and show URL’s and stuff, just let me know. I’m not running on localhost.

iameric
# 4
iameric

I am having the issue as well… the popup shows the code of the error page, once you scroll down to get to the message it says something about the form being expired.

Laisvunas
# 5
Developer
Laisvunas

Hi,

Please, post here your essential template code and URL of the page having the issue.

iameric
# 6
iameric

Thank you for the quick reply.

In my case, here is the code from my main template…

{embed="includes/aside_pagination" ajax_pagination_vars="category" ajax_pagination_values="{categories}{category_id}{/categories}"

it is called within a channel entries tag so the category is loaded depending on the subject being sought.

Then in the embedded template…

{exp:ajax_pagination:wrapper
 ajax_container
="ajax_container"
 
embed_template_url="{site_url}/includes/aside_pagination"
 
ajax_pagination_vars="{embed:ajax_pagination_vars}"
 
ajax_pagination_values="{embed:ajax_pagination_values}"
 
xid_element_id="infinite_scroll_xid"
 
parse="inward"
 
}

{ajax_pagination_container_top}
<ul id="ajax_container" class="related_cases">
{/ajax_pagination_container_top}

{exp
:channel:entries 
  channel
="results" 
  
category="{ajax_pagination_embed_category}"
  
dynamic="off"
  
disable="member_data"
  
limit="10"
  
paginate="bottom"
  
}
 
<li class="{switch='odd|even'}"><class="fa fa-folder"></i> <a href="{site_url}results/casefile/{url_title}">{title}</a></li>

 
{paginate}
 {exp
:ajax_pagination:links}
 
<li class="pagination"
  
{if previous_page}
            
<a href="{auto_path}">Previous 10</a> | 
        
{/if}
        {if next_page}
            
<a href="{auto_path}">Next 10 Results</a>
        
{/if}
 
<li>
 
{/exp:ajax_pagination:links}
 {
/paginate}
{
/exp:channel:entries}

{ajax_pagination_container_bottom}
</ul>
{/ajax_pagination_container_bottom}



{
/exp:ajax_pagination:wrapper} 

Finally, the URL of the actual page is (REMOVED LINK) - it is a development site for an actual customer. The issue, you will see, is in the right sidebar.

Thank you!!!

iameric
# 7
iameric

Bump?

Laisvunas
# 8
Developer
Laisvunas

Hi iameric,

It seems that in your embedded template input element having property id with the value of “infinite_scroll_xid” is lacking.

So, try to add this code just beneath of ajax_pagination_container_top tag:

<input type="hidden" id="infinite_scroll_xid" value="{XID_HASH}"

 

iameric
# 9
iameric

Hi - Thank you for your help!

It does indeed work, but with one exception - in the case of the example page I sent above, it loads the 2nd batch of ten items. However, trying to load a third batch now gives an error box saying “No response from server.” then it loads up the 1st ten.

Any recommendations for that?

Thank you!

iameric
# 10
iameric

Hi Laisvunas,

Please disregard the last message - I found that I had not closed the li tag, and I didn’t include the closing > of the opening li (oops) - after I found those errors, everything works perfectly as advertised.

Thanks very much, love the addon!

Best,
Eric