PDA

View Full Version : Ajax tootip - problem with ajax syntax?



Rainymountain
04-03-2017, 09:13 AM
Hello,

I'm working with this script: Ajax Tooltip http://www.javascriptkit.com/script/script2/ajaxtooltip.shtml .

Within the same domain, it works properly. But when I write a different domain URL as source, it doesn't, although I have granted CORS permissions on that other domain.

Example:
<a class="showTip" href="#INFO" title="ajax:../00/page1.htm">page 1</a> works,

but neither
<a class="showTip" href="#INFO" title="ajax:http://www.example.com/page2.htm">page 2</a>
nor
<a class="showTip" href="#INFO" title="ajax:www.example.com/page2.htm">page 2</a>
work.

What I am doing wrong?

jscheuer1
04-03-2017, 05:22 PM
Well the access control is key, but as long as that's set properly on the remote page, the script syntax splits the title attribute on : and uses the second segment. So your first non-working example is seen as just "http" and the second one is missing the protocol (needed for all off site links), so won't work either.

However, as long as the protocol is the same as the local page, you can use '//' to imply it:


<a class="showTip" href="#INFO" title="ajax://www.example.com/page2.htm">page 2</a>

In general this will only work on a live page (or a local host server that uses the same protocol as the requested page), and only if both the requesting page and the requested page are the same protocol (both http: or both https:).

NOTE: Untested, but should work. The browser cache may need to be cleared, and/or the page refreshed to see results.

Rainymountain
04-05-2017, 08:06 AM
John, many thanks, it works!

(Am I stupid! Something actually told me that the http: was too much and the www. too less, but I wasn't thinking of the //. The tree hiding the forest. :mad:)