dongpu9481
2014-05-14 15:57
浏览 50
已采纳

Jquery移动ajax加载页面

i want to load data from my php file into my jquery mobile page. I need to send data pageid(php variable) to my php file to run the query. I want to load the the content from my php file while loading #topics page in jquery from my topics file.

here is my onclick anchor:

$pageid = 1;
<a class="clickme" href="#topics_main_id" onClick="load_page(<?php echo $pageid;?">Content</a>

here is my script:

<script>
$( document ).on( "pageinit" function( event ) {
    function load_page(id){
        $.ajax({
            type: "POST",
            url: "topic01.php",
            data: {
                    pageid: id
                },
                success: function(content) {
                    $("#thema").html(content);
                }
        });

        return false;
    }
});
</script>

here is my php file:

<?php
    $pageid = $_POST["pageid"];
    $abfrage = "SELECT * FROM topics WHERE id='$pageid'";
    $ergebnis = $db->query($abfrage);
    while($row = $ergebnis->fetch_assoc()){
        $topic = $row["topic"];
    }
?>
<span style="font-weight: bold; font-size:  13pt;">Thema</span><br> <span style="font-weight: normal;"><?php echo  $topic; ?></span>

this #topics_main_id is a div content="page", that i want to get the html from my php file in. I want it to load into the span id="#thema" in my div container #topics_main_id

Can anyone help me please? i try to load this dynamically, is it possible?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doushouxie7064 2014-05-14 20:33
    已采纳

    You're missing the closing bracket and parenthesis in your anchor. Otherwise, without trying it, it appears solid at first glance.

    EDIT: Looks like you're missing a comma between "pageinit" and function. and it's not a good idea to pass the POST parameters directly into your SQL query. That should be sanitized/verified as a valid value prior.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题