我有两个页面,一个帖子值到另一个,然后它进行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.
}
?>
答案 0 :(得分: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解码的值。