2012-12-13 2 views
0

knockout.js 웹 사이트의 기본 자습서 중 하나를 따랐으므로 이제는 localhost에서 작동하도록 노력하고 있습니다. 머리 부분에는 knockout.js와 misc_form.js의 두 파일이 포함되어 있습니다. knockout.js가 PHP와 함께 작동하는 데 문제가 있습니다

<head> 
<script src="/knockout.js"></script> 
<script src="/misc_form.js"></script> 
</head> 

나는 내가 그것을 수정하지 않았기 때문에 misc_form.js에 대한 코드를 생략 할거야 그리고 라이브 knockout.js 튜토리얼에 100 % 작동합니다.

다음은 HTML을

//form.php 
function display_form(){ 
?> 
<table> 
    <thead><tr> 
    <th>Passenger name</th><th>Meal</th><th>Surcharge</th><th></th> 
    </tr></thead> 
    <!-- Todo: Generate table body --> 
    <tbody data-bind="foreach: seats"> 
    <tr> 
     <td><input data-bind="value: name" /></td> 
     <td><select data-bind="options: $root.availableMeals, value: meal, optionsText: 'mealName'"></select></td> 
     <td data-bind="text: formattedPrice"></td> 
     <td><a href="#" data-bind="click: $root.removeSeat">Remove</a></td> 
    </tr>  
</tbody> 
</table> 
<button data-bind="click: addSeat">Reserve another seat</button> 
<? 
} 

편집이다 - 나는 파일의 경로를 변경하고 지금은 그

Uncaught TypeError: Cannot read property 'nodeType' of null //in reference to knockout.js 
+0

http : //localhost/misc_form.js로 변경하면 작동하지 않습니다. – user1852176

답변

1

스크립트 파일에 대한 경로를 확인 다음과 같은 오류를 받고 있어요 이상하게 보입니다. 웹 브라우저에서 http://localhost/Applications/XAMPP/xamppfiles/htdocs/misc_form.js을 방문해보십시오. 자바 스크립트 코드가 보이십니까? URL과

, 나는 그들이해야 같은데요 : htdocs 이후

<head> 
<script src="/knockout.js"></script> 
<script src="/misc_form.js"></script> 
</head> 

가능성이 /로까지 제공됩니다 폴더입니다.

+0

작동하도록했습니다.하지만 작동하지 않으면 시작하지 않을 것입니다. 당신의 팁! 다른 사람이 제안한대로 스크립트 파일을 으로 변경했습니다. http://stackoverflow.com/questions/9128015/knockout-syntax- 오류 – user1852176

+0

좋은 반갑습니다. 나는 네가 다니엘의 대답을 보았다는 것을 알았다. 제임스의 대답도 봐 가치가있다. 'defer = "defer"'는 브라우저에 스크립트를로드하기 전에 페이지 dom을로드 할 수 있다고 말하면서 [.ready()] (http://api.jquery.com/ready/)는 페이지 dom * 반드시 스크립트 전에로드해야합니다. – Douglas

관련 문제