아래의 자바 스크립트 기능이 페이지를 한 번 새로 고친 후에 만 작동하는 이유는 무엇입니까? 페이지 하단에 기능을 넣으려고했지만 여전히 작동하지 않습니다. 코드가 실행되는 순서와 관련이 있다고 생각하지만 어디에서 구체적으로 식별 할 수는 없습니다. Javascript는 처음 새로 고침 후에 만 작동합니까?
function incrementIssue(id) {
var row = "#row" + id;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("issue"+id+"Upvote").innerHTML=xmlhttp.responseText;
//$(row.toString()).find('.ui-icon').removeClass('ui-icon-custom').addClass('ui-icon-arrow-d');
}
}
xmlhttp.open("GET","incrementIssue.php?q="+id,true);
xmlhttp.send();
}
</script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="docs/themes/blue/jquery.mobile-1.2.0.css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
</head>
<body>
<div data-role="page" id="pageone">
<div data-role="header">
<h1>Pithy</h1>
<div data-role="navbar">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="issues.php">View Issues</a></li>
<li><a href="add.php">Add Issue</a></li>
</ul>
</div>
</div>
<div data-role="main" class="ui-content">
<ul data-role="listview" data-inset="true" data-split-theme="c" >
<?php
mysql_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($dbname);
//Fetching from your database table.
$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
if ($result) {
while($row = mysql_fetch_array($result)) {
$issue = $row["issueName"];
$upvotes = $row["upvotes"];
$id = $row["issueID"];
echo "<li data-icon=\"arrow-u\" id=\"row".$id . "\"> <a data-transition=\"pop\" href=\"point.php?id=". intval($id). "\">".$issue ."</a><a href=\"javascript:incrementIssue(".$id.");\"></a> <span id=\"issue".$id."Upvote\" class=\"ui-li-count\">" .$upvotes."</span></li>";
}
}
?>
</ul>
</div>
<div data-role="footer">
<h6>See what's important.</h6>
</div>
</div>
</body>
</html>
으로 제한 시간을 제공하기 위해이'incrementIssue는()'기능을 수행합니다 한 번만 실행하지 않습니까? – ArinCool