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.
}
?>
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.
精彩评论