2010-01-05 5 views
0

[http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery#Rate_me:_Using_Ajax]에이 등급 스크립트가 있는데 아무 것도 나타나지 않으면 http://jquery.bassistance.de/example-rateme.html의 예와 같이 작동하지 않는 것 같습니다.JQuery와 PHP 속도 스크립트?

이 문제를 어떻게 해결할 수 있습니까?


여기 아래에 전체 스크립트입니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
<title>jQuery Starterkit</title> 

<link rel="stylesheet" type="text/css" media="screen" href="css/screen.css" /> 
<script src="jquery.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 
    // generate markup 
    var ratingMarkup = ["Please rate: "]; 
    for(var i=1; i <= 5; i++) { 
     ratingMarkup[ratingMarkup.length] = "<a href='#'>" + i + "</a> "; 
    } 
    var container = $("#rating"); 
    // add markup to container 
    container.html(ratingMarkup.join('')); 

    // add click handlers 
    container.find("a").click(function(e) { 
     e.preventDefault(); 
     // send requests 
     $.post("starterkit/rate.php", {rating: $(this).html()}, function(xml) { 
      // format result 
      var result = [ 
       "Thanks for rating, current average: ", 
       $("average", xml).text(), 
       ", number of votes: ", 
       $("count", xml).text() 
      ]; 
      // output result 
      $("#rating").html(result.join('')); 
     }); 
    }); 
}); 
</script> 

</head> 
<body> 
<h1>jQuery Getting Started Example - rate me</h1> 

<?php 

define('STORE', 'ratings.dat'); 

function put_contents($file,$content) { 
    $f = fopen($file,"w"); 
    fwrite($f,$content); 
    fclose($f); 
} 

if(isset($_REQUEST["rating"])) { 
    $rating = $_REQUEST["rating"]; 
    $storedRatings = unserialize(file_get_contents(STORE)); 
    $storedRatings[] = $rating; 
    put_contents(STORE, serialize($storedRatings)); 
    $average = round(array_sum($storedRatings)/count($storedRatings), 2); 
    $count = count($storedRatings); 
    $xml = "<ratings><average>$average</average><count>$count</count></ratings>"; 
    header('Content-type: text/xml'); 
    echo $xml; 
} 

?> 

<p>This example demonstrate basic use of AJAX. Click one of the links below to rate. The 
number of rating and the average rating will be returned from the serverside script and displayed.</p> 

<div id="rating">Container</div> 

</body> 
</html> 

답변

1

자바 스크립트 오류를 ​​가져 오거나 볼 때 파이어 버그를 사용하십시오 ... Firefox에서 오류 콘솔을 확인할 수도 있습니다. 무슨 일이 일어나고 있는지 알지 못하면 문제를 해결하기가 어렵습니다.

바보 같은 질문이지만 서버에 jquery.js이 있습니까?

2

o jsquery를 확인하십시오. JQuery와 질문은 유효 - 현재 디렉토리에 나를 위해, 그것은 "JQuery와-1.4.2.js"입니다 (유효한 JQuery와 소스 파일을 가리키는 있는지 확인

속도의 위치를 ​​확인합니다. . .PHP 예 - rateme.html는 폴더 starterkit에 rate.php을 찾을 것으로 예상 출하 파일을 하나 개의 폴더에 모두 -.. 그래서,이 문제를 해결

오 PHP 세션이 켜져 있어야합니다. 내 PC에서 내 테스트 서버에 설치된 기본 PHP는 session.auto_start 플래그가 해제 된 ini 파일을 사용합니다 (http://www.learnphp-tutorial.com/Sessions.cfm).

o 서버를 다시 시작하고 캐시를 비우고 작은 동물을 희생하십시오. 나는 약간의 농담을하고있다. 그러나 잠시 후 사라지는 문제를 쫓는 데 많은 시간을 할애했다. 내가 생각하기에 나는 업데이트 된 것으로 생각되는 파일의 이전 버전을 돌리고 있었기 때문이다.