jQuery load works on Dreamweaver but not in browsers

╄→гoц情女王★ 提交于 2019-12-25 05:04:59

问题


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.



来源:https://stackoverflow.com/questions/20230615/jquery-load-works-on-dreamweaver-but-not-in-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!