简体   繁体   中英

using jquery .ajax or .get to receive content from database via php script

I have this php script to communicate to mysql right now, and it displays in tab number 2:

$res = mysql_query("SELECT K_id, title FROM headings WHERE 
  MATCH (title) AGAINST('$kquery') ORDER BY 
  MATCH (title) AGAINST('$kquery') DESC");
  while ($result = mysql_fetch_array($res)){
        $kid= $result['K_id'];
        echo "<h1>{$result['title']}</h1>";
        $content = mysql_query("SELECT content, url, id FROM kparagraphs WHERE K_id = '$kid' LIMIT 3");
        while ($con = mysql_fetch_array($content)){
            echo $con['content'];
        }
        }

what I'm also doing is actually selecting/loading content into the database in tab number one. I wanted the content to be displayed in tab number 2 as it is being loaded via ajax. How could I do this in jquery with php?

how would I pass data to the file...the php script starts with $kid = $_GET['title']....title is enocoded in the url. How can I pass this along using the mentioned answer that uses.load?

1.) Create the page you want loaded via ajax using your code above and echo out the result.

2.) Create two div's for your content that you can later turn into tabs if you want, assign their id values as mydiv1 and mydiv2

3.) At the top of the page with div1 and div2 make sure you have the jquery script loaded and then add some code like:

<script type="text/javascript">
  $('div#mydiv2').load('url_to_the_file_you_created_with_div_2_content');
</script>

Try using:

$.ajax({url:'page.php',success:function(data){
    // play with data
}});

If I understand your request...this should work:

$.get("thescript.php", function (html) {
      $("#tab2").html(html);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM