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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题