Javascript – Mixed Content Error (Http/Https)

ajaxhttphttpsjavascriptjquery

I have mixed content error, on web site used both http and https protocols.

Here's the error from Chrome console:

Mixed Content: The page at 'https://www.amazon.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://www.amazon.com/../?redirect=true'. This request has been blocked; the content must be served over HTTPS.

Here's screenshot with the error: http://prntscr.com/9os5li

Was found some solution like:

Change link from "http://" to "https://" in
Blocked loading mixed active content.

Nothing helped me, because Amazon server drop it all the time when I change link in code or manual from http to https drop it and make it as http.

For example this one Link 2 I can't use here https, because of this I have mixed content error.

Here's my AJAX where I make a call:

$.ajax({
            url: "//" + MWS_URL + rest_path,
            data: request,
            dataType: 'text',
            type: 'POST',
            contentType: 'application/x-www-form-urlencoded; charset=utf-8',
            beforeSend: function(req) {
                //req.setRequestHeader("User-Agent", "chrome extension");
                req.setRequestHeader("x-amazon-user-agent", "chrome extension");
            },
            success: function(data){
                if (onSuccess) {
                    onSuccess(data);
                }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                if (onError) {
                    onError(jqXHR, textStatus);
                }
            }
        });
        setTimeout(callService, 1000);
    }

Request:

requests.push(
                    $.get(link.URL, function (data) {
                        if (IsCancel()) {
                            return;
                        }
                        var jdata = $($.parseHTML(data));
                        var parser = new ProductPageParser(jdata, link.URL);
                        if (!parser.isValidProduct()) {
                            console.log(link.URL + " is not a valid product, skipped.");
                            link.processed = true;
                            return;
                        }

                        // Process associated (linked) product on this page according to user preferences.
                        crawlLinkedProducts(jdata, link.URL, config);

                        // Store product into a collection.
                        var product = getProductForParser(parser, link);
                        //product.dbRawProductURL = urlRaw;
                        if (product) {
                            products.push(product);
                        }
                        link.processed = true;
                    })
                );

And as I have parse in parser, here's second level parser. I parsed products on main page:

$(productUrls).each(function (index, link) {
                        if (!link.processed) {
                            console.log("Download second level -> " + link.URL);
                            requests_2level.push(
                                $.post(link.URL, "", function (data) {
                                    if (IsCancel()) {
                                        return;
                                    }

                                    console.log("End download second level -> " + link.URL);
                                    var jdata = $($.parseHTML(data));
                                    var parser = new ProductPageParser(jdata, link.URL);

                                    if (!parser.isValidProduct()) {
                                        console.log(link.URL + " is not a valid product, skipped.");
                                        link.processed = true;
                                        return;
                                    }

                                    var hackUrl = "//amazon.com/o/ASIN/" + parser.getAsin();
                                    link.URL = hackUrl;
                                    var product = getProductForParser(parser, link);
                                    if (product) {
                                        products.push(product);
                                    }
                                    link.processed = true;
                                })
                            );

                        }
                    });

Anyone have idea how to fix this problem?

Best Answer

If Amazon keep redirecting you from HTTPS to HTTP then there is nothing you can do about that short of:

  • Complaining hard enough at Amazon that they fix it or
  • Using a difference service