In many instances, one can omit the protocol altogether. So, instead of
<img src="https://test.com/image.jpg" />
one could use
<img src="//test.com/image.jpg" />
The browser then adds the current protocol automatically. This also works for including files in the head, and it should also work for ajax calls.
Edit: Doing this is now considered to be an anti-pattern:
Now that SSL is encouraged for everyone and doesn’t have performance concerns, this technique is now an anti-pattern. If the asset you need is available on SSL, then always use the https:// asset.
Allowing the snippet to request over HTTP opens the door for attacks like the recent Github Man-on-the-side attack. It’s always safe to request HTTPS assets even if your site is on HTTP, however the reverse is not true.
see: http://www.paulirish.com/2010/the-protocol-relative-url/