Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top