jquery json post返回整个页面html

发布于 2024-11-06 07:52:37 字数 1539 浏览 0 评论 0原文

我有两个页面,一个将值发布到另一个页面,然后它进行 mysql 查询并将数据返回到第一个页面。如果我使用jquery json post,而不是jquery ajax post,如何取回整个页面? (我想取回mysql查询结果)。谢谢。

<html>
<head>
<script type='text/javascript' src='jquery-1.4.2.min.js'></script>
<script type="text/javascript">

$(document).ready(function(){
    $("#submitbutton").click(function(){
      $.ajax({
         url: "m2.php", 
         dataType: "json",
           data: "number1="+$('#number1').val(), 
         success: function(json){
            //$("#result").html(json.number1);// original json data get, it can success.
            $("#result").load('m2.php');//jquery load only load an empty page...
         }
      });
    });
});
</script>
  </head>
  <body>
    <input name="number1" id="number1" value="today" type="text" />
    <input type="submit" value="Calc" id="submitbutton" name="submitbutton"/>
    <div id="result"></div>
  </body>
</html>


<?php
 $db = @mysql_connect("localhost","root","root") or die("can not connect Mysql Server");
 mysql_select_db("contact",$db); 
 $number1 = $_GET['number1'];
 $arr = array(); 
 $arr['number1'] = $number1;
 //echo json_encode($arr); // original json encode data, back to the first page 
 $searchword = json_encode($arr);
 $result = mysql_query("SELECT * FROM msg where title like '%$searchword%' Order By id DESC Limit 0,10");
 while($row = mysql_fetch_array($result)){
    echo $row['name'];// This is what I want get the data. 
 }
?>

I have two pages, one posts value to another, then it makes a mysql query and returns the data to the first one. If I use jquery json post, instead of jquery ajax post, how to get back the whole page back? (I want get back the mysql query results). Thanks.

<html>
<head>
<script type='text/javascript' src='jquery-1.4.2.min.js'></script>
<script type="text/javascript">

$(document).ready(function(){
    $("#submitbutton").click(function(){
      $.ajax({
         url: "m2.php", 
         dataType: "json",
           data: "number1="+$('#number1').val(), 
         success: function(json){
            //$("#result").html(json.number1);// original json data get, it can success.
            $("#result").load('m2.php');//jquery load only load an empty page...
         }
      });
    });
});
</script>
  </head>
  <body>
    <input name="number1" id="number1" value="today" type="text" />
    <input type="submit" value="Calc" id="submitbutton" name="submitbutton"/>
    <div id="result"></div>
  </body>
</html>


<?php
 $db = @mysql_connect("localhost","root","root") or die("can not connect Mysql Server");
 mysql_select_db("contact",$db); 
 $number1 = $_GET['number1'];
 $arr = array(); 
 $arr['number1'] = $number1;
 //echo json_encode($arr); // original json encode data, back to the first page 
 $searchword = json_encode($arr);
 $result = mysql_query("SELECT * FROM msg where title like '%$searchword%' Order By id DESC Limit 0,10");
 while($row = mysql_fetch_array($result)){
    echo $row['name'];// This is what I want get the data. 
 }
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

试试这个:

$strName = '';
while($row = mysql_fetch_array($result)){
    $strName .= $row['name'];// This is what I want get the data. 
}
echo json_encode($strName);

在你的 html 页面中使用 json 解码值。

Try this:

$strName = '';
while($row = mysql_fetch_array($result)){
    $strName .= $row['name'];// This is what I want get the data. 
}
echo json_encode($strName);

In your html page use json-decoded value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文