简体   繁体   中英

loading external javascripts with GAE

I'm having some trouble loading external javascripts using google app engine. I basically have an index.html file with the following on the header section:

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

and the following in the body section:

<p id="demo"></p>
<button  type="button" onclick = DisplayDate() >Display Date</button>

In the jsfunctions.js file, I have:

function DisplayDate(){
    document.getElementById("demo").innerHTML=Date();
}

When I run this, I can see that the page gets the jsfunctions.js:

INFO 2012-05-06 00:37:25,864 dev_appserver.py:2884] "GET /jsfunctions.js HTTP/1.1" 404 

However, nothing happens when I click on the button.

Am I missing something important here?

Unless you declare a static_files entry for jsfunctions.js (or put it in a subdirectory that you declare with static_dir ), your handler has to be prepared to serve it.

See https://developers.google.com/appengine/docs/python/config/appconfig#Static_Directory_Handlers

The transfer log entry says 404, that means your js file was not loaded. Double check that it is being served when you enter the URL to the file.

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