jQuery与PHP表单元素json_encoded

时间:2014-10-24 02:31:24

标签: php jquery input

我基本上得到了我在php中制作的表单元素。原因是当我调用数据库时,我希望我的表包含所有内容。我想我只是json_encode这一切。它显示出很棒的一切。但是,由于某种原因,我无法使用任何表单元素。

有什么能阻止它正常运作吗? 如果不发布一连串的代码,这里有一个简短的突触:

网站按钮ajax调用php调用。 - php文件调用数据库并创建一个包含数据库中信息的表,以包含我拥有的格式化输入类型。 - php文件json_encodes这一切。 - 我通过jQuery ajax调用成功地将所有内容返回到页面。

当我尝试console.log(“test”)其中一个无线电功能时,它什么也没显示。这是非常奇怪的,因为我在其他地方使用了成功的代码,其中的代码不是通过PHP从json_encode生成的。

我会发布代码,小心,我不是那么好哈哈。

if (isset($_POST['getWeek'])) { 
    $getLeague = mysql_real_escape_string($_POST['league']);
    $getWeek = mysql_real_escape_string($_POST['getWeek']);
    if ($_POST['getWeek'] != "Week #") { 
    //match listing for Pilot Modification
        $table = "
            <form action=''  method='post'>
<input type='hidden' name='s' value='{vb:raw session.sessionhash}' />
<input type='hidden' name='securitytoken' value='{vb:raw bbuserinfo.securitytoken}' />
            <table class='tg' style='undefined;table-layout: auto; width: 100%; margin: auto;'>
                <colgroup>
                <col style='width: 21px'>
                <col style='width: 157px'>
                <col style='width: 21px'>               
                <col style='width: 157px'>
                <col style='width: 21px'>
                <col style='width: 157px'>
                <col style='width: 21px'>
                <col style='width: 151px'>
                <col style='width: 20px'>
                <col style='width: 157px'>
                <col style='width: 21px'>
                <col style='width: 157px'>
                <col style='width: 21px'>
                <col style='width: 157px'>
                <col style='width: 21px'>
                <col style='width: 159px'>
                </colgroup>
                <tr>
                <td class='tg-a0td'></td>
                <td class='tg-1rn1'>MatchNum</td>
                <td class='tg-a0td'></td>
                <td class='tg-1rn1'>Player</td>
                <td class='tg-a0td'></td>
                <td class='tg-1rn1'>Mech</td>
                <td class='tg-a0td'></td>
                <td class='tg-1rn1'>Status</td>
                <td class='tg-031e'></td>
                <td class='tg-1rn1'>Match Score<br></td>
                <td class='tg-a0td'></td>
                <td class='tg-1rn1'>Kills</td>
                <td class='tg-a0td'></td>
                <td class='tg-1rn1'>Assists<br></td>
                <td class='tg-a0td'></td>
                <td class='tg-1rn1'>Damage</td>
                </tr>";
        $query = mysql_query("SELECT * FROM vb_mwo_scoreboard WHERE league='$getLeague' AND week='$getWeek' ORDER BY week, league", $con) or die("Query failed: <font color='red' size='2>getWeek</font>" . mysql_error());
        while($r = mysql_fetch_array($query)) {
            $mech = htmlentities($r['mech'], ENT_QUOTES);//html special chars
            if ($r['status'] == 0) { $status = "Alive"; } 
            if ($r['status'] == 1) { $status = "Dead"; } 
            $score = $r['score'];
            $kills = $r['kills']; 
            $assists = $r['assists']; 
            $damage = $r['damage']; 
            $player = $r['player']; 
            $matchNum = $r['matchNum'];
            $radio = "<span class='dataSelected'><font size='1'><input type='button' name='$player' id='modify' value='Modify'></font></span>";
            //$radio = htmlentities($radio, ENT_QUOTES);
            $table .= "

            <tr>
                <td class='tg-031e'>$radio</td>
                <td class='tg-031e'><span class='dataSelected'><span id='mMatchNum'>$matchNum</span></span></td>
                <td class='tg-031e'></td>               
                <td class='tg-031e'><span class='dataSelected'><span id='mPlayer'>$player</span></span></td>
                <td class='tg-031e'></td>
                <td class='tg-031e'><span class='dataSelected'><span id='mMech'>$mech</span></span></td>
                <td class='tg-031e'></td>
                <td class='tg-031e'><span class='dataSelected'><span id='mStatus'>$status</span></span></td>
                <td class='tg-031e'></td>
                <td class='tg-031e'><span class='dataSelected'><span id='mScore'>$score</span></span></td>
                <td class='tg-031e'></td>
                <td class='tg-031e'><span class='dataSelected'><span id='mKills'>$kills</span></span></td>
                <td class='tg-031e'></td>
                <td class='tg-031e'><span class='dataSelected'><span id='mAssists'>$assists</span></span></td>
                <td class='tg-031e'></td>
                <td class='tg-031e'><span class='dataSelected'><span id='mDamage'>$damage</span></span></td>
            </tr></form>";
            $json = array(
            'match' => $matchNum,
            'table' => $table,
            'radio' => $radio,
            'mech' => $mech,
            'status' => $status,
            'score' => $score,
            'kills' =>$kills,
            'assists' => $assists,
            'damage' => $damage,
            'player' => $player
        );
        }
        $table .= "</table>";
        echo json_encode($json);
    }
}

现在我所有显示数据的代码都正常运行。一切都按照我的意图行事。在下一点。我试图简单地测试按钮,看看我是否得到了console.log(“test”)。它没有发生。

$("#modify").click(function () {
console.log("clicked");
});

它表现得像没有形式。从我所知道的。我还必须在PHP中执行整个表格,因为如果我试图在主页面中执行该操作并将其余部分包含在内,那么它就像拆分一样。似乎事情在某种程度上被抑制了。我不知道jQuery有限制吗?

0 个答案:

没有答案