0

I am using some JavaScript in my ASP.Net page like this:-

<script type="text/javascript" src="MyScript.js"></script>
<script type="text/javascript">
    function validate_everything()
    {
        do_foo();
    }
</script>

where MyScript.js exists in the same directory as the Default.aspx, and contains this (only):-

function do_foo()
{
    var fred = 2;
    return fred;
}

When I attempt to run this (using Internet Explorer) it produces the error:-

0x800a1391 - JavaScript runtime error: 'do_foo' is undefined

The real code (with actual useful work) handled in the same way was working fine yesterday, and fine earlier this morning. I modified it and this error started appearing; I reverted the changes and the error still appears. Before, using Chrome, the real version worked. Now, nothing happens (I assume the reason is the same).

I appreciate this question is a hardy perennial. My problem differs from those here and here in that I'm not using JScript, and this one in that I'm not adding the script from the code-behind.

I have used this approach in several other applications and the error does not occur there. Is that path going to pick up the file from the Default.aspx directory? Is there anything I need (in web.config or anywhere else) that I am lacking?

Edit on inspecting the page source (Chrome) the JavaScript in the .aspx file is listed as expected. The included file is shown thus:

<script type="text/javascript" src="MyScript.js"></script>

but no script is shown (ought there to be?)

10
  • Is MyScript.js definitely being loaded by the browser? If so, is it the right version? (You may need to do a cache refresh) Commented Dec 24, 2015 at 10:51
  • Open Developer Tools in Chrome, and see if reports an error when trying to load MyScript.js. Go to the Sources tab and see if MyScript.js is listed. Commented Dec 24, 2015 at 10:51
  • @Barmar, I did as you suggested; the results are in the edit. Commented Dec 24, 2015 at 10:55
  • If it's not showing the script, it got an error while trying to load it. Go to the Network tab and then reload the page. Commented Dec 24, 2015 at 10:56
  • Is that the correct path? could it be src="/MyScript.js"? If you browse http://localhost/MyScript.js is it served? Commented Dec 24, 2015 at 10:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.