gpt4 book ai didi

php - jquery json post返回整个页面html

转载 作者:行者123 更新时间:2023-12-01 05:05:54 25 4
gpt4 key购买 nike

我有两个页面,一个将值发布到另一个页面,然后它进行 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.
}
?>

最佳答案

试试这个:

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

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

关于php - jquery json post返回整个页面html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5949334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com