简体   繁体   中英

Access to restricted URI denied. Firebug

I have 1 HTML Page and 1 js file . I cannot run script in Firebug on Chrome
it shows following Error :

Access to restricted URI denied.

Code is as per tutorial

HTML Page

<!DOCTYPE html >
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>jQuery Example </title>
</head>
<body>
    <input type="button" value="Hide" id="toggle_messege" />
    <p id="messege">
        You see this paragraph
    </p>
    <script type="text/javascript" src="~/js/toggle.js"></script>
    <script type="text/javascript" src="~/js/jquery-1.7.1.min.js"></script>
</body>
</html>

js file

$('#toggle_messege').click(function () {
    var value = $('#toggle_messege').attr('value');
    $('messege').toggle('fast');
    if (value == 'Hide') {
        $('#toggle_messege').attr('value', 'Show');
    }
    else if (value == 'Show') {

        $('#toggle_messege').attr('value', 'Hide');
    }
});

Similar post : Error: "Access to restricted URI denied"

http://jquery-howto.blogspot.in/2008/12/access-to-restricted-uri-denied-code.html

They suggest it is same domain policy issue and solution is to access file from webserver(localhost)

my url is

 http://localhost/WebApplication2/js/

But couldnot solve the issue .. plz suggest if something missing

You have errors in your code

1.Change the order of file , jquery reference is first

<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>    
<script type="text/javascript" src="js/toggle.js"></script>

2.You code must be wrapped in $(document).ready() and it should be in <head> block

$(document).ready(function(){
$('#toggle_messege').click(function () {
    var value = $('#toggle_messege').attr('value');
    $('#messege').toggle('fast'); // You missed # in this line
    if (value == 'Hide') {
        $('#toggle_messege').attr('value', 'Show');
    } else if (value == 'Show') {

        $('#toggle_messege').attr('value', 'Hide');
    }
});
});

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM