简体   繁体   English

使用 jquery.ajax or.get 通过 php 脚本从数据库接收内容

[英]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:我现在有这个 php 脚本来与 mysql 通信,它显示在标签号 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.我希望内容显示在标签号 2 中,因为它是通过 ajax 加载的。 How could I do this in jquery with php?我怎么能在 jquery 和 php 中做到这一点?

how would I pass data to the file...the php script starts with $kid = $_GET['title']....title is enocoded in the url.我如何将数据传递给文件... php 脚本以 $kid = $_GET['title'].... 开头,标题在 url 中编码。 How can I pass this along using the mentioned answer that uses.load?我如何使用上面提到的uses.load答案传递这个?

1.) Create the page you want loaded via ajax using your code above and echo out the result. 1.) 使用上面的代码创建您想要通过 ajax 加载的页面并回显结果。

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 2.) 为您的内容创建两个 div,如果需要,您可以稍后将其转换为选项卡,将它们的 id 值分配为 mydiv1 和 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: 3.) 在页面顶部的 div1 和 div2 确保您已加载 jquery 脚本,然后添加一些代码,例如:

<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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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