jQuery load works on Dreamweaver but not in browse

2019-09-18 16:56发布

问题:

I used the .load() function. It works in Dreamweaver's Live View, but not in Firefox, Chrome, or IE.

Here is my HTML section:

<script src="js/jquery.js"></script>
<script src="tabsPull.js"></script>
<h1>Homework Assignments</h1>
<ul id="button-menu">
    <li id="a1"><input class="no" type="button" onClick="ChangeActive(1)" value="Mon"></li>
    <li id="a2"><input class="no" type="button" onClick="ChangeActive(2)" value="Tues/Wed"></li>
    <li id="a3"><input c    lass="no" type="button" onClick="ChangeActive(3)" value="Thurs/Fri"></li>
</ul>
<div id="tabInner" class="tabInner">

</div>

The ChangeActive() is in a separate JS file (tabsPull.js):

var active = 0
function ChangeActive(active){
    if (active==1) {
        document.getElementById("a1").className = "active";
        document.getElementById("a2").className = "";
        document.getElementById("a3").className = "";
        $('#tabInner').load('http://axoplanner.weebly.com/monday.html #content');
    } else if (active==2) {
        document.getElementById("a2").className = "active";
        document.getElementById("a1").className = "";
        document.getElementById("a3").className = "";
        $('#tabInner').load('http://axoplanner.weebly.com/tuesdaywednesday.html #content');
    } else if (active==3) {
        document.getElementById("a3").className = "active";
        document.getElementById("a1").className = "";
        document.getElementById("a2").className = "";
        $('#tabInner').load('http://axoplanner.weebly.com/thursdayfriday.html #content');
    }
}

What's the problem? It works in DW, but why not the browsers??? The reason I pull things from Weebly is because I need others to update it, and Weebly is easier.

回答1:

See this page from the jQUery documentation.

From the Documentation:

"Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol."

So, DreamWeaver must not have the security restrictions that most browsers have, so it works in DreamWeaver. But an absolute path will not work as an argument for .load() in most browsers.