1

I have my site build on Laravel and using onscroll pagination at frontend with JScroll JavaScript plugin.

I have properly setup my server and it is automatically redirecting to HTTPS. And when I access my site through my IP address on https, the pagination works perfectly without any issue but when I point my domain to the IP address the pagination is not working and requesting paginated URL on HTTP protocol due to which the request is getting blocked by browser due to mixed content.

My site is using Cloudflare as CDN and for DNS resolver. I have also enabled HTTPS on Cloudflare and automatic https redirect through Cloudflare. But still I am getting the same error.

I think it JScroll and jQuery that are causing the issue.

JScroll plugin link : https://github.com/pklauzinski/jscroll

Infinite Scroll pagination working through this below code:

<script type="text/javascript">
    $('ul.pagination').hide();
    $(function() {
        $('.scrolling-pagination').jscroll({
            autoTrigger: true,
            padding: 20,
            nextSelector: '.pagination li.active + li a',
            contentSelector: 'div.scrolling-pagination',
            callback: function() {
                $('ul.pagination').remove();
            }
        });
    });
</script>

Here is the console error:

Mixed Content: The page at 'https://example.com/posts/all' was loaded over HTTPS, 
but requested an insecure XMLHttpRequest endpoint 'http://example.com/posts/all?page=3'. 
@ jquery.min.js:4  
This request has been blocked; the content must be served over HTTPS. 
send    @   jquery.min.js:4 
ajax    @   jquery.min.js:4 
n.fn.load   @   jquery.min.js:4 
(anonymous) @   jquery.jscroll.min.js:1 
d.complete  @   jquery.min.js:3 
i   @   jquery.min.js:2 
add @   jquery.min.js:2 
_a  @   jquery.min.js:3 
g   @   jquery.min.js:3 
dequeue @   jquery.min.js:3 
(anonymous) @   jquery.min.js:3 
each    @   jquery.min.js:2

How can I resolve this issue?

Update

I found the issue but not able to resolve it. Actually, when content loads through AJAX request the returned rendered HTML data do not contain HTTPS pagination URL. I am using this code to return html response on AJAX call

$html = view('ajaxData', ['data' => $data, 'filtersArray' => $filtersArray])->render(); 
echo $html;

And in Blade file I am using this code to generate pagination content:

{{ $data->appends($filtersArray)->links() }}
halfer
  • 19,824
  • 17
  • 99
  • 186
  • "when I point my domain to the IP address the pagination is not working" - (1) is this via HTTP rather than HTTPS? (2) If there is some configuration in your site that hardwires the domain version even when you are using the IP address, you need to find that config and change it, so that it uses your IP address. – halfer Feb 19 '23 at 22:23
  • My domain uses HTTPS protocol to load, there no configuration error on my site – Jessica Shamoon Feb 20 '23 at 07:18
  • But the "requested an insecure XMLHttpRequest endpoint" error indicates that something in your front/back stack is using non-secure HTTP. – halfer Feb 20 '23 at 10:38
  • I found the issue but not able to resolve it. Actually, when content loads through AJAX request the returned rendered html data do not contain HTTPS pagination url. I am using this code to return html response on AJAX call ```$html = view('ajaxData', ['data' => $data, 'filtersArray' => $filtersArray])->render(); echo $html; ``` and in blade file I am using this code to generate pagination content: ```{{ $data->appends($filtersArray)->links() }} ``` – Jessica Shamoon Feb 20 '23 at 12:28
  • So the HTML in the AJAX response is using non-HTTPS links. Where is it getting those links from? It sounds like the server is rendering the wrong protocol type. Could they be hardwired in a Blade template? – halfer Feb 20 '23 at 12:42
  • May be the the server is rendering the wrong protocol type. Yes, it can be hardwired in Blade template, but is there any core solution to this issue. But I have not checked hardwired. – Jessica Shamoon Feb 20 '23 at 12:56
  • Laravel auto generate those pagination links – Jessica Shamoon Feb 20 '23 at 13:05
  • OK. So the pagination device needs something to be changed. How does the `links()` method work? Can you supply options to it? Is this part of Eloquent, or a plugin, etc? Have you looked at the code implementation of it? (I am not suggesting you _should_ hardwire anything - I had wondered if you _had_ hardwired something, which was the cause of this problem). – halfer Feb 20 '23 at 13:57
  • Hi Halfer, Thank you for your time and effort on my question. I found the solution. In AppServiceProvider::boot method I added add the following to force https on everything including pagination links ```if($this->app->environment('production')) { $this->app['request']->server->set('HTTPS','on'); }``` – Jessica Shamoon Feb 20 '23 at 14:48
  • Great stuff Jessica. Please add that information to a self-answer using the blue Answer Your Question button below. Thanks! – halfer Feb 20 '23 at 15:03

1 Answers1

0

I found the solution and the issue has been resolved.

In the Laravel AppServiceProvider AppServiceProvider::boot method, I added the following code to force HTTPS on everything, including pagination links.

if($this->app->environment('production')) {    
   $this->app['request']->server->set('HTTPS','on'); 
}