jQuery AJAX Request to HTTPS getting served to HTTP with Laravel and Select2
Asked Answered
P

1

1

I have a relatively simple Laravel app, that features an HTML form which contains a tag select element. The select element gets enhanced via select2 library. The tags are fetched via an XMLHttpRequest. I've created a fiddle, and the error I receive there is the same as on my production machine:

[...]was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://blog.mazedlx.net/tags?term=asd'. This request has been blocked; the content must be served over HTTPS.

$('#tags_id').select2({
    minimumInputLength: 2,
    tags: true,
    tokenSeparators: [','],
    ajax: {
        url: 'https://blog.mazedlx.net/tags/',
        type: 'GET',
        dataType: 'json',
        data: function (params) {
            var queryParameters = {
                term: params.term
            }
            return queryParameters;
        },
        processResults: function (data) {
            return {
                results: $.map(data, function (item) {
                    return {
                        text: item.tag,
                        id: item.id
                    };
                })
            };
        }
    }
});

As you can see in the fiddle the ajax url contains https, and the page containing the form is also served over https. The url also yields results: e.g. https://blog.mazedlx.net/tags?term=php. What am I doing wrong?

Pleasant answered 15/3, 2016 at 10:43 Comment(6)
If you check in the console you can see the request is going to the http:// protocol, not https://, hence the errorExcel
as you can see in the code, the ajax call goes to a https resourcePleasant
The code says it does, but the console is king: i.imgur.com/9jzpgyZ.pngExcel
so, where do i start debugging? even if the request comes via http my server is configured to redirect to https, always.Pleasant
Hey @mazedlx, try using a secure middleware in laravel & let us know the results. See: laracasts.com/discuss/channels/tips/…Relate
I'd rather let the web server handle insecure requests, but, ok. Created a middleware that will redirect to secure if the request is unsecure. I check for $request->secure() but it returns false although the page is served via https. I am not behind any proxy oder hoster.Pleasant
P
1

Solved it. Needed to modify my Apache conf for that vhost. The SSL directives where only loaded for the main domain, but not for that subdomain.

Pleasant answered 15/3, 2016 at 13:26 Comment(1)
what did you modify ?Hostage

© 2022 - 2024 — McMap. All rights reserved.