0
私はトピックの位置とトピックをgetTopics()
関数で返そうとしています。たとえば、 "楽器"を返すと整数0が返され、getFaqs()
関数で使用できます。 "プログラミング言語"を返すと、整数1なども返されます。私はパラメータtopic_id(整数)とトピック(テキスト)を含めたので、なぜこの関数が動作しないのか分かりません。php配列のアイテムの位置整数をPHPからHTMLにするには?
のindex.html:
function getTopics() {
$.getJSON("topics.php", function(result) {
$("#topic-container").html("");
$.each(result, function(topic_id, topic){
$("<div>", {id: topic_id , text: topic, onclick: "getFaqs(this.id, $(this).text())"}).appendTo($("#topic-container"));//pass topic_pos
});
});
return false;
}
topics.php:
<?php
header('Content-Type: application/json; charset=utf-8');
$topics = array("Musical instruments", "Programming languages", "Varieties of pizza");
?>
あなたは魔法のように何を期待していますそのPHPで起こる?たぶん 'echo json_encode($ topics);' – AbraCadaver