2014-01-10 3 views
1

이것은 Stackoverflow에 대한 첫 번째 게시물입니다. 내가 놓친다면 안내해주세요. 외부 자바 스크립트 파일로 HTML5 개발을하고 XAMPP 3.2.1 서버에서 동일한 내용을 테스트하려고합니다. "HF_Chapter10_WebWorkers_Example1"을 XAMPP 설치의 "C : \ xampp \ htdocs"에 저장했으며 Javascript 파일 "manager.js"도 같은 폴더에 있습니다. 'manager.js'는 내부적으로 작업자 스레드를 생성하고이를 호출합니다.XAMPP에서 HTML로 외부 Javascript 파일을 얻으려면

문제 : Google 크롬에서 HTML 파일을 열 때 참조 된 외부 Javascript 파일을 찾을 수 없음을 나타내는 Chrome 도구의 404가 표시됩니다. 또한, 서버가 'text/HTML'대신 'text/javascript'로 javascript 파일을로드하는 것을 볼 수 있습니다. 내가 appender 타입을 시도했다 '텍스트/자바 스크립트'자바 스크립트 호출하지만 그 중 도움이되지 않았다. 이 문제의 이유를 이해하려고합니다. 이것은 HTML 파일로가는 것입니다

:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)"> 
    <meta name="dcterms.created" content="Wed, 08 Jan 2014 05:07:11 GMT"> 
    <meta name="description" content=""> 
    <meta name="keywords" content=""> 
    <title>HF_Chapter10_WebWork_Example1</title> 

    <LINK REL="stylesheet" HREF="theme.css" TYPE="text/css"> 

<script type="text/javascript" src="manager.js"> </script> 
</head> 
<body> 
<p id="output"> ![enter image description here][1]</p> 
</body> 
</html> 

이것은 자바 스크립트 파일에가는 것입니다 'manager.js'

window.onload = function() { 
    //create the worker thread 
    var worker = new Worker("worker.js"); 

    //send the message to the worker thread 
    worker.postMessage("ping"); 

    //create an event listener to act on the messages arriving from the worker thread 
    worker.onmessage = function(event) { 
     var message = "Worker says" + event.data; 
     document.getElementById("p").innerhHTML = message; 
    } 
} 

이것은 worker.js 파일에가는 것입니다 :

onmessage = pingPong; 
function pingPong(event) { 

    //based on the type of data, respond back with the 'postMessage'. 
    //Note that the message will go to the main javascript handler 
    if (event.data == "ping") { 
     postMessage("pong"); 
    } 
} 
+0

폴더 구조의 스크린 샷을 –

+0

캡처했습니다. 스크린 샷을 첨부했습니다. 솔루션에 대한 아이디어가 있습니까? – user3180655

+0

이 파일을 어떻게 실행합니까? 더블 클릭 만하면됩니까? –

답변

0

명확하지 무엇은 (404)를 생성하지만, 이것은 당신에게 도움이 될

폴더 구조의 이미지를 첨부하고 있습니다. Here's the image of the folder structure

관련 문제