Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple jQuery code works fine until site is loaded via https://

Tags:

jquery

https

I have a simple peice of jQuery code that submits a form and hides/shows some on screen information. It works fine when tested, until loaded via https:// upon which it breaks in IE7. It appears to break totally, with none of the script having any effect. I also get the IE warning that "some elements are insecure".

Does anyone have any experience of this happening? Or even better, a solution! I have to load the page via https as its a credit card payment page.

like image 262
Shealan Avatar asked Jun 29 '09 03:06

Shealan


People also ask

How do I make sure jQuery is loaded?

In general, you just use the following basic "document loaded" test in jquery. Straight from the beginners jquery tutorial: $(document). ready(function() { // do stuff when DOM is ready });

What is jQuery and how it works?

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.

Why jQuery is not working in HTML?

Be sure to import the jQuery library before your custom script is loaded. You will need to go the jQuery CDN and suss out a recent version 1 minified CDN URL. Go to the page “View all versions” (or something like that) and copy the link address of the minified version for 1.9. 3 or 1.10.


2 Answers

The three previous answers all mention the problem of a secured "https" page trying to include scripts or other resources (stylesheets, images, etc) from an "http" path...

I would like to add to these, and note that if you have a situation where the same pages could be loaded via either http or https, then you can create "protocol-less" URLs---the protocol will be assumed to be the same as the current page. Note this is only needed for accessing resources on different domains (and will only work if those different domains support both http and https), because obviously if you're accessing resources on the same domain, you don't need to start with http:// at all...

For example, each of these three resources would assume either http or https depending on how the current page was accessed:

<script src="//www.example.com/whatever.js" type="text/javascript"></script> <img src="//www.example.com/someimage.png" alt="whatever" /> <link href="//www.example.com/styles.css" rel="stylesheet" /> 
like image 164
Funka Avatar answered Nov 14 '22 09:11

Funka


If you serve a page via https:// then every resource link should also use https://. Look out for

<script type="text/javascript" src="http://.../jquery.js"></script> 
like image 36
John Kugelman Avatar answered Nov 14 '22 08:11

John Kugelman