Invalid pagination url

I have two pagination in a single page. The first pagination is on the sidebar and the second is showing in the modal. I have no problem with the first one, it uses the template page pagination url.

However in the modal pagination its different.

Im throwing variable ‘id’ in the plugin and get its results and append it to a modal.

	   $.ajax({
			url: url + '/api/get-templateid',
			data: { id: templateid },
			dataType: 'json',
			method: 'post',
			success: function(data, responseText){
				$('.preview-modal').append(data.snippet);
			},
			error: function(data, responseText) {
			}
		})

when I checked the $pagination->pageUrl(). its showing
http://localhost:8885/xxxx/api/get-templateid/page:2

Its getting the url of the plugin. making my pagination not to work. it says 404 not found.

@texnixe

What plugin are you talking about?

I made a plugin that pass array to snippets.

    function getTemplateID() {
$snippet = array( 'status' => 0, 'message' => 'An error has occurred.' );
$templateid = $_POST['id'];

// Open the file using the HTTP headers set above
$url = file_get_contents(c::get('api').'user/' . s::get('hasAccess') . '?api_token=' . s::get('hasToken'));
$user = json_decode($url);

$capsule_items_url = file_get_contents(c::get('api').'capsule-template/'.$templateid.'/item');
$capsule_items = json_decode($capsule_items_url);

$capsule_templates_url = file_get_contents(c::get('api').'capsule-template/'.$templateid);
$capsule_templates = json_decode($capsule_templates_url);

$capsule_plan_url = file_get_contents(c::get('api').'capsule-plan/'.$capsule_templates->capsule_plans_id);
$capsuleplan = json_decode($capsule_plan_url);

$get_item_paginate = new Collection($capsule_items);
$pagination = $get_item_paginate->paginate(1)->pagination();

$snippet = snippet('capsule-type/preview-capsule-type', compact('user', 'url', 'hasAccess', 'capsule_items', 'capsule_templates', 'capsuleplan', 'pagination', 'get_item_paginate'), true);


return $snippet;

}

And what is the URL it should get?

I think your Ajax call should actually only return the currently requested page instead of the complete collection, but not sure.

Where is this method called, in a route?

Edit: You should configure your pagination object, these are the defaults:

  public static $defaults = array(
    'variable'      => 'page',
    'method'        => 'param',
    'omitFirstPage' => true,
    'page'          => false,
    'url'           => null,
    'redirect'      => false,
  );

Its getting the url from route.

array(
    // 'pattern' is the url being called from our form's ajax javascript function
	'pattern'=> 'api/get-templateid',
	'method' => 'POST',
	'action' => function() {
        // get the query which is part of the URL.
		$data = getTemplateID();
		// $data['success'] = true;
		return response::json($data);
	}
)

Where I am going to put that?

$options = [
    'url'  => url('api/get-templateid')
  ]; 
$pagination = $get_item_paginate->paginate(1, $options)->pagination();

@ryuchix Did this solve your issue?

No. I tried your solution but I cant make it work. Have you tried multiple pagination in the same page? Does it work?

Because of that, i decided to remove the sexond pagination.

No, I haven’t but someone did in the past. Maybe you can solve it with this post:

I will try that once i encouter another multiple pagination in a project again.

Thanks again @texnixe